conditional expression evaluation
Gregory Smith
greg at utcsri.UUCP
Sat Jan 17 02:40:36 AEST 1987
In article <2356 at brl-adm.ARPA> rgenter at j.bbn.com (Rick Genter) writes:
>Not only that, but it was outright wrong. Since the only guarantee on ++
>is that it will be evaluated before the start of the next statement, the
>compiler is free to implement the expression as:
>
> if ( (booltemp = *cp | *cp | *cp, cp += 3, booltemp) ) {
> ...
> }
>
True;
>or, alternatively,
>
> if ( (cp += 3, *cp | *cp | *cp) ) {
> ...
> }
>
False.
At least one of the *cp's will reference one of cp[0],cp[1],cp[2]
(using the original value of cp), since the post-increment was used.
The following might be generated:
if ( (cp += 3, cp[-1] | cp[-1] | cp[-1]) ) {
which references cp[2] three times. In fact it seems to me that any
legal ordering of *cp++|*cp++|*cp++ will generate references to
old_cp[0], old_cp[1] and old_cp[2] only, but I won't try to prove it.
Our Ns32k compiler often does "*p++" as "++p, p[-1]", and it
is conceivable that three ++cp could be folded into cp += 3 as above.
--
----------------------------------------------------------------------
Greg Smith University of Toronto UUCP: ..utzoo!utcsri!greg
Have vAX, will hack...
More information about the Comp.lang.c
mailing list