Evaluation of function arguments (w

wsmith at uiucdcsb.cs.uiuc.edu wsmith at uiucdcsb.cs.uiuc.edu
Sat Sep 27 05:53:00 AEST 1986


>int i;
> i = 0;
>f ( i++, i++, i++);
>write(i);
> f( a,b,c) int a,b,c;
>  write (a,b,c);
>
Because the expression being used in your program is un-defined in
the C language, lint complains about such non-sensical programs,
saying evaluation order undefined.

Your program could be translated into something like this:
	load   r0,i
	pusharg r0
	load   r1,i
	pusharg r1
	load   r2,i
	pusharg r2
	inc    r2
	load   i,r2
	inc    r1
	load   i,r1
	inc    r0
	load   i,r0
	call	f
	....


In which case, the program would print out:
0 0 0
1
Another possibility that will probably generate fewer flames is:
0 0 0
3

I don't know of a compiler that does such nonsense, but I think one could.

A safer program is
main()
{
int i;
f(g(&i),g(&i),g(&i));
write(i);
}
f(a,b,c)  int a,b,c;
{ write (a,b,c); }
g(pi) int * pi;  
{ return( (*pi)++ ); }

Bill Smith
ihnp4!uiucdcs!wsmith
wsmith at a.cs.uiuc.edu



More information about the Comp.lang.c mailing list