[Interest] QStringList, takeFirst and order of execution
Giuseppe D'Angelo
giuseppe.dangelo at kdab.com
Mon Nov 11 13:50:08 CET 2013
Il 11/11/2013 13:37, Samuel Gaist ha scritto:
> Hi,
>
> I have been experiencing a strange behavior with QStringList and the order of execution of takeFirst.
>
> The following code:
>
> QString line = file.readLine(); // line contains "46 71\n"
> QStringList lineData = line.split(); // lineData contains ("46", "71\n")
> qDebug() << lineData.takeFirst() << lineData.takeFirst();
I've already explained this in the past but I can't find the relevant
email. This last line is parsed as
> operator<<( operator<<( qDebug(), lineData.takeFirst() ) , lineData.takeFirst() )
(operator<< is left associative).
Take the outer operator<<. C++ does not define the order of evaluating
its parameters. That means that either lineData.takeFirst() can be
called before evaluating the inner operator<<, or vice-versa. Depending
on what the compiler chooses to do, you'll have a different result.
HTH,
--
Giuseppe D'Angelo | giuseppe.dangelo at kdab.com | Software Engineer
KDAB (UK) Ltd., a KDAB Group company
Tel. UK +44-1738-450410, Sweden (HQ) +46-563-540090
KDAB - Qt Experts - Platform-independent software solutions
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 4048 bytes
Desc: Firma crittografica S/MIME
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20131111/c0c66c57/attachment.bin>
More information about the Interest
mailing list