c99 - Does comma separators in type definition in C guarantee the order? -


comma operators have lowest precedence , left-to-right associativity, guarantees order like:

i = ++j, j = i++; 

i 2, , j 1 after statement if i , j both 0 @ first.

however, comma separators in type definition in c guarantee order? such as

int = 1, j = ++i; 

your example comma operator, i = ++j, j = i++;, well-defined because comma operator sequence point.

precedence/associativity not enough guarantee -- different order-of-evaluation , sequence points. example, i * 2 + i++ * 3 undefined because there no sequence points.


the comma separator between declarators, e.g. int = 1, j = i++;, sequence point. covered c11 6.7.6/3, c99 6.7.5/3:

a full declarator declarator not part of declarator. end of full declarator sequence point.

so there sequence point after i = 1, , code well-defined.


however, comma separator between function arguments f(i, i++) not sequence point; code causes undefined behaviour.


note: in c11, term sequence point replaced more complicated sequencing relations in order specify threading model, not affect above discussion.


Comments

Popular posts from this blog

facebook - android ACTION_SEND to share with specific application only -

python - Creating a new virtualenv gives a permissions error -

javascript - cocos2d-js draw circle not instantly -