06.08.2013 Views

Threads in the new ISO C Standard from 2011

Threads in the new ISO C Standard from 2011

Threads in the new ISO C Standard from 2011

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Sequenced Before<br />

The most common sequence po<strong>in</strong>t <strong>in</strong> C/C++ is semicolon.<br />

O<strong>the</strong>rs <strong>in</strong>clude:<br />

Function call<br />

Comma operator<br />

After evaluat<strong>in</strong>g <strong>the</strong> left operand of ?:, && and ||.<br />

Below at L, <strong>the</strong> assignment to and use of v not sequenced.<br />

<strong>in</strong>t u = 1, v = 2, w;<br />

L: w = (v = u + 3) + v * 4;<br />

It is legal C but <strong>the</strong> value of w can become ei<strong>the</strong>r 12 or 20.<br />

It is due to it is unspecified which operand of + is evaluated first.<br />

In <strong>the</strong> follow<strong>in</strong>g w becomes 20 s<strong>in</strong>ce comma is a sequence po<strong>in</strong>t.<br />

w = (v = u + 3), v * 4;<br />

Jonas Skeppstedt (js@cs.lth.se) Lecture 6 2013 27 / 70

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!