delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/07/15/20:16:54

Sender: nate AT cartsys DOT com
Message-ID: <378E79DC.8A2A350@cartsys.com>
Date: Thu, 15 Jul 1999 17:16:28 -0700
From: Nate Eldredge <nate AT cartsys DOT com>
X-Mailer: Mozilla 4.08 [en] (X11; I; Linux 2.2.10 i586)
MIME-Version: 1.0
To: djgpp AT delorie DOT com
Subject: Re: question about if statements!
References: <19990715204430 DOT 18320 DOT rocketmail AT web105 DOT yahoomail DOT com> <7mlk0u$8aj AT dfw-ixnews14 DOT ix DOT netcom DOT com>
Reply-To: djgpp AT delorie DOT com

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019