side effects in argument lists

Chris Torek chris at mimsy.UUCP
Wed Nov 30 21:48:37 AEST 1988


In article <1077 at mina.liu.se> mikpe at mina.liu.se (Mikael Pettersson) writes:
>Consider the following program:

[edited]
>void bletch(int junk) { printf("count == %d\n", count); /* 0 or 1 ? */ }
>main() { bletch(count++);

>This program exemplifies the situation where the behaviour of the
>callee depends on whether the caller has completed *all* of the
>side effects from evaluating the arguments of the call or not.

>Q: what sayeth the dpANS about this?

The dpANS sayeth that the program is to print `1'.  All side effects
are to have completed by the next `sequence point'.  The list of
sequence points includes comma expressions, `&&', `||', and not
least, function calls.  Obviously, statement bounardies (semicolons)
are sequence points as well.

>If count++ _is_defined_as_ (++count, count-1) then I guess things
>are cool, but what if the definition is less strict?

The definition is less strict, but the side effect is done by the
next sequence point.  Insert a sequence point and your side effect
is guaranteed; without it, it is not.
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163)
Domain:	chris at mimsy.umd.edu	Path:	uunet!mimsy!chris



More information about the Comp.lang.c mailing list