Denotational Semantics and Language Standards

Jeffrey Kegler jeffrey at algor2.algorists.com
Sat Nov 11 18:26:34 AEST 1989


PH> Article <813 at ccssrv.UUCP> perry at ccssrv.UUCP (Perry Hutchison)
JK> Article <1989Nov9.151708.3617 at algor2.algorists.com>
   jeffrey at algor2.algorists.com (Jeffrey Kegler)

JK> the result of
JK> 
JK> int f(int a, int b) { return a+b; }
JK> ...
JK> i = 2; i = f(i = 3, i);
JK> 
JK> is indeterminate.  Variable i can be either 5 or 6, after this

PH> It can also be 3.  In fact, it is probably legal for i to have any value
PH> whatsoever, or for the program to dump core.

I checked this before posting.  Evaluation order of arguments is
covered by 3.3.2.2 which treats this as unspecified behavior, not
undefined behavior.  (See also A.6.1).  So no core dumps are allowed
in conforming implementations.

As for 3 being a possible result, the function call is a sequence
point (A.2 and 3.3.2.2), as is the expression in the return statement
(3.6).  So the addition must be performed prior to the assignment
(2.1.2.3).
-- 

Jeffrey Kegler, Independent UNIX Consultant, Algorists, Inc.
jeffrey at algor2.ALGORISTS.COM or uunet!algor2!jeffrey
1762 Wainwright DR, Reston VA 22090



More information about the Comp.std.c mailing list