[Interest] QStringList, takeFirst and order of execution

Samuel Gaist samuel.gaist at edeltech.ch
Mon Nov 11 16:33:09 CET 2013


On 11 nov. 2013, at 13:42, Thiago Macieira <thiago.macieira at intel.com> wrote:

> On segunda-feira, 11 de novembro de 2013 13:37:20, Samuel Gaist wrote:
>> Hi,
>> 
>> I have been experiencing a strange behavior with QStringList and the order
>> of execution of takeFirst.
> 
>> qDebug() << lineData.takeFirst() << lineData.takeFirst();
> 
> The problem is not takeFirst.
> 
>> behaves differently on two computers.
> 
> Correct. You have undefined behaviour.
> 
> Both calls to takeFirst() are in the same "sequence-point". That means the 
> compiler is allowed to execute in any order.
> 
> It would be the same if you had written:
> 
> 	f(lineData.takeFirst(), lineData.takeFirst());
> 
>> qDebug() << lineData.takeFirst();
>> qDebug() << lineData.takeFirst();
>> 
>> The order is correct on both of them.
>> 
>> What could explain the difference ?
> 
> In the second case, there are two sequence points (they are separated by a ;). 
> 
> In C++11-speak, the first line of the second example is guaranteed to "happens-
> before" the second line. In the first example, there's no "happens-before", 
> therefore any one can happen before the other, or after.

I see, thanks for the explanation !




More information about the Interest mailing list