short circuit evaluation
m5d at bobkat.UUCP
m5d at bobkat.UUCP
Wed Jan 28 07:03:05 AEST 1987
In article <5178 at mimsy.UUCP> chris at mimsy.UUCP (Chris Torek) writes:
>>>>[ he's quoting me here ]
>>>>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'.
>>>>Mike McNally Digital Lynx Inc.
>
>Not so!
>
I know, I know, I'm sorry, I'm sorry!
> [
> Chris then goes on to accurately describe the possible
> paths of evaluation for |, &, ||, and &&, although he
> omits ^, which is OK I think, because you can't say
> much about ^ given an intermediate result
> ]
>
>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
I realize that my first posting(s? I can't remember how many I did)
were a little confused. I do know what's going on, and would like to
ask a related question.
If the compiler decides to generate code that notices when part of a
sequence of sibling `|' or `&' operations have generated an inevitable
result, do side effects of sub-expressions still have to be performed?
In other words, let's look at this:
x = f1(something) | f2(something) | f3(something) ...
If I wrote this, I would expect all the functions to be called, even if
one of them returns ~0. Am I nuts? Seems to me that an optimization
like that would be naughty.
As I look at that example, I realize that people might still think I'm
confused. Try this example:
x = f1(something) * f2(something) * f3(something) ...
Shouldn't I expect all the multiplications to be performed, even if one
function returns zero?
I don't think I've ever used a compiler that does such optimizations
(not that that really means much). Has anyone else?
If I actually *am* lost, please don't tell my employer.
--
**** ****
**** At Digital Lynx, we're almost in Garland, but not quite ****
**** ****
Mike McNally (feeling sheepish nowadays) Digital Lynx Inc.
Software (not hardware) Person Dallas TX 75243
uucp: {texsun,killer,infotel}!pollux!bobkat!m5d (214) 238-7474
More information about the Comp.lang.c
mailing list