short circuit evaluation
chris at mimsy.umd.edu
chris at mimsy.umd.edu
Thu Feb 12 08:12:08 AEST 1987
Dan Hoey <hoey at nrl-aic.arpa> writes:
> From: Henry Spencer <utzoo!henry>
>
> I did ask Dennis about [a PDP-11 C compiler short circuiting
> multiplies by constant zeroes, thus discarding side effects]
> at one point, since strict reading of K&R suggested it was a
> bug. His reply, as I recall it, was roughly "I think it is
> defensible in principle, but it caused so many complaints that
> newer versions of the compiler don't do it".
>
>Are your cases of justifiable pornography sufficiently specific that
>they should appear in the standard? I believe the standard must be
>precise here, and the ``so many complaints'' lead me to believe that
>the answer must be in favor of guaranteed execution of side-effects.
I would prefer to see some guarantee that side effects will occur.
Guarantees as to precisely *when* are problematical, and since such
have never been made, should not be part of the standard. So let
us say that
if (*p++ & *q++)
and
a = *p++ * *q++;
and even
a = 0 * *p++ * *q++;
must always increment both p and q, but not in any particular order,
so long as the memory references use the values p and q have before
they are incremented.
Should we also say that the memory references in the third expression
must occur? If not, the compiler can optimise this into
p++, q++, a = 0;
but if so, must the compiler also do the multiply? (It might
overflow, which could be important.)
--
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7690)
UUCP: seismo!mimsy!chris ARPA/CSNet: chris at mimsy.umd.edu
More information about the Comp.lang.c
mailing list