conditional expression evaluation question
Mike McNally
m5d at bobkat.UUCP
Sat Jan 17 06:40:41 AEST 1987
My small contribution to this silly topic:
x = (*cp++ | *cp++ | *cp++); (1)
if (x) ... /* or !x or whatever */
In computing the value to be assigned to the variable `x', the compiler
cannot short-circuit the expression. This should be clear; in the
simpler case
x = (a | b | c);
if the variable `a' contains zero, the compiler must still OR the
contents of `b' and `c' to determine the result. These are bitwise
logical operators. Short-circuiting these makes no more sense than
short-circuiting a sequence of multiplies as soon as one of the
operands evaluates to `1'.
I of course agree that a potential problem exists with (1) above. If
the evaluation of `*cp++' is not atomic, and the increment could be
delayed, the result may be equal to the first byte of the series. In
any case, `cp' must be incremented by `3' and both bitwise-OR operations
must be performed. Oh well, I guess an optimizing compiler that
delays the increments might realize this and skip the OR's...this
is getting ridiculous.
--
**** ****
**** At Digital Lynx, we're almost in Garland, but not quite ****
**** ****
Mike McNally Digital Lynx Inc.
Software (not hardware) Person Dallas TX 75243
uucp: {texsun,killer,infotel}!pollux!bobkat!m5 (214) 238-7474
More information about the Comp.lang.c
mailing list