Theory of Pure C, chapter 937 - (nf)

utzoo!decvax!yale-com!leichter utzoo!decvax!yale-com!leichter
Thu Dec 23 09:49:44 AEST 1982


It usually says somewhere in most language manuals that the arguments get
evaluated before the function is called.  I don't know off-hand whether
this particular wording appears in the C manuals, but it's a fairly obvious
way to describe how f(<complex-expression>) works.  In fact, something like
that is necessary, redundant as it sounds, if you allow side-effects in
function arguments - f(getc()), for example, had better call getc() before
f() gets started up.  (One COULD have a call-by-need semantics in which getc()
doesn't get evaluated until f() actually needs its value.  This sort of thing
works well in side-effect-free languages, but obviously fails here.)

SO, what John is really asking is:  What is part of "evaluating" x++ - just
the extraction of the old value, or both the extraction and the increment?
This is never clearly defined, as far as I can tell, in any C document,
although given the origin of the post-fix ++ - the PDP-11 auto-increment
instruction - it's clear that what was intended was for "evaluate" to
include both steps.  Hence, the function should see the updated value
when it looks in the global.

(If you don't make this the interpretation, things can get awfully muddy.
Consider:

	f(foo)
	int	foo;
\\\ cancel that, no editor;

	int *f(foo)
	int	foo;
\\\ugh, this isn't going to fly "on the fly" as it were.  The idea is:
Take John's function but also return the address of x; the make the
calling expression is:

	y = *f(x++);

Does y get the new or the old x?  If we decide that x gets incremented
AFTER f gets called (so that f sees the old global x) - how much after?
After or before the assignment to y?
						-- Jerry
					decvax!yale-comix!leichter
						leichter at yale



More information about the Comp.lang.c mailing list