Indirect comma assigned from side effects
Tomas Rokicki
rokicki at navajo.STANFORD.EDU
Wed Aug 20 05:08:29 AEST 1986
[ `---\- For the plane eater ]
The question is whether the comma operator (which K&C guarantees will
evaluate its left operand before its right operand) may allow parts of
other expressions in the same statement to be evaluated somewhere in
the middle of the comma operands evaluation.
For example, consider the program:
int lhs, rhs, index; int *pointers[9];
foo() { *( index=lhs, pointers[index] ) = sideeffects(); }
The question is, does C allow for the possibility that the order
of evaluation might be "index=lhs" then "sideeffects()" then
"*pointers[index]=<result>"? If so, then if "sideeffects()"
changes the value of "index", then the result of the statement
is not defined. On the other hand, if C does not allow the
compiler to generate such code, then the statement is well
defined.
I realize that in general, K&C say that the order of expression
evaluation is not defined, but in certain circumstances it is,
and their wording does not make it totally clear (to me, anyway)
whether this case is covered.
More information about the Comp.lang.c
mailing list