What should a C compiler do? - (nf)

darryl at ism780.UUCP darryl at ism780.UUCP
Thu Mar 29 14:49:03 AEST 1984


#R:mprvaxa:-50100:ism780:12500001:000:887
ism780!darryl    Mar 27 16:03:00 1984

Very clearly #1 is wrong.  K&R says "The usual arithmetic
conversion is peformed on the expression, but the result must
be int."

I don't find anything disturbing about #2 at all.  The result of
b++ is the original value of b.  After it has been used in
computing the expression, it is incremented.  Several places in
K&R mention that the only way to specify evaluation order in an
expression is to write several expressions, assigning results
to temps.

In fact, the reason that you get different code is easily
explained:  normally the actual increment is put off until after
evaluation of the expression is complete -- this is what you get
for "a = b++ + b;".  But since the result of the expression
"if( a = b++ + b ) ;" might result in a branch before the end of
the statement, the increment is done right after b is fetched, the
first time.

	Darryl Richman  ...!ima!ism780!darryl



More information about the Comp.lang.c mailing list