Article View: net.lang.c
Article #9161Indirect comma assigned from side effects
From: Tomas Rokicki
Date: Tue, 19 Aug 1986 19:08
Date: Tue, 19 Aug 1986 19:08
24 lines
1528 bytes
1528 bytes
[ `---\- 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.
Technical Details
Message-ID:
<792@navajo.STANFORD.EDU>Path:
arc1-ca.pugleaf.net!utzoo!mnetor!seismo!ll-xn!nike!oliveb!glacier!navajo!rokickiShow Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: arc1-ca.pugleaf.net!utzoo!mnetor!seismo!ll-xn!nike!oliveb!glacier!navajo!rokicki From: rokicki@navajo.STANFORD.EDU (Tomas Rokicki) Newsgroups: net.lang.c Subject: Indirect comma assigned from side effects Message-ID: <792@navajo.STANFORD.EDU> Date: Tue, 19-Aug-86 15:08:29 EDT Article-I.D.: navajo.792 Posted: Tue Aug 19 15:08:29 1986 Date-Received: Wed, 20-Aug-86 23:11:34 EDT Organization: Stanford University Lines: 24