ambiguous ?

Geoffrey Rogers grogers at sushi.uucp
Tue Oct 17 06:00:35 AEST 1989


In article <20974 at gryphon.COM> bagpiper at pnet02.gryphon.com (Michael Hunter) writes:
>In the following code fragment is line 3 ambiguous from an X3J11 standpoint
>or from a historical standpoint.
>
>1) int Ret ;
>2)
>3) func(Ret = func2(), Ret+30) ;
>
>I wouldn't normally write code like this, but I ran across code similar to
>this in a program I am maintaining, and, as long as it isn't ambigous to some
>large subset of the existing compilers, I will probably leave it be.
>

In both K&R I and pANSI C the evaulation order of parameters being pass 
to a function is undefined. This means that if you compile the above code 
with two different compilers you could get two different answers!

You should rewrite the code as follows:

1) int Ret ;
2)
3) Ret = func2() ;
4) func(Ret, Ret+30) ;

Geoffrey C. Rogers



More information about the Comp.lang.c mailing list