Mail Archives: djgpp/1999/07/15/20:16:54
Marp wrote:
>
> Mohamed Saad <bazramit AT yahoo DOT com> wrote in message
> news:19990715204430 DOT 18320 DOT rocketmail AT web105 DOT yahoomail DOT com...
> > does djgpp continue to evaluate an expression of
> > an if statement even if the result is readily
> > available?
> > i.e. consider this...
> > if (0&&dummy1)
> > statement here;
> >
> > well it evaluate dummy1??
>
> No. As a shortcut (for speed) if the left side of the && operator is false,
> the right side won't be tested. Similarly, with the || operator, if the left
> side is true, the right side won't be tested. I think you can safely rely on
> this behavior for all C and C++ compilers, but I'm not absolutely sure of
> that.
I am. It's required behavior for the C language.
Some languages (like sh and Perl) (ab)use this as a control structure.
i.e.
open(FOO, "foo") || die;
--
Nate Eldredge
nate AT cartsys DOT com
- Raw text -