tags:

views:

46

answers:

2

I've looked at SO/IEC 9899:201x under J.1 Unspecified behavior:

"The order in which subexpressions are evaluated and the order in which side effects
take place, except as specified for the function-call (), &&, ||, ?:, and comma
operators (6.5)."

Does this means that in

func1() + func2();

func2() may be preformed before func1(), or even during func1() ?

+1  A: 

Not during, but sure, either 1 then 2 or 2 then 1.

wrang-wrang
Thanks, why not during?
Liran Orevi
The contents of a function that's called aren't themselves sub-subexpressions :)
wrang-wrang
@Liran: see section **6.5.2.2 Function calls** /10 and also the note 84) `In other words, function executions do not ``interleave'' with each other.`
pmg
Many thanks @pmg (b.t.w loved your website `)).
Liran Orevi
+4  A: 

In the current standard (ISO/IEC 9899:1999) there is a sequence point between function calls but the order of evaluation of the operands to + is not specified so func1 may be called before or after func2 but the function calls must not overlap or be interleaved in any way.

This means that each of func1 and func2 can, if desired, interact with some shared data without having that data change under it in an unexpected way.

Charles Bailey
yes, the plus operator is a sequence point, see http://en.wikipedia.org/wiki/Sequence_point
just somebody
In the current standard: 6.5/10, I believe.
Charles Bailey
The plus operator itself doesn't imply a sequence point, but because it's arguments are both function calls there are two sequence points before + is evaluated.
Charles Bailey