From: loafman AT gte DOT net (Kenneth Loafman) Newsgroups: comp.os.msdos.djgpp Subject: Re: [Q] expression evaluation order Date: 7 Aug 1997 17:31:25 GMT Organization: Loafman Software Lines: 26 Message-ID: <5sd0pd$k66$1@gte1.gte.net> References: <5sbb1h$kvr$1 AT newton DOT pacific DOT net DOT sg> Reply-To: loafman AT gte DOT net NNTP-Posting-Host: dfw73123.gte.net Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-2022-JP Content-Transfer-Encoding: 7bit To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk On Thu, 07 Aug 1997 17:15:11 GMT, xfesenko AT pacific DOT net DOT sg (Victor) wrote: >Is it safe to assume that the expression > >if(first_function()==OK && second_function()==OK && >third_function()==OK) return(OK); > >will be evaluated from left to right? > >Regards. >Victor Fesenko Yes, its called "Short Circuit Evaluation". In an ANDing expression, the expressions will be evaluated from left to right UNTIL one returns false. I say this because, in your example, some functions may not be evaluated at all and that could be a surprise if your are not expecting it. The best example of this is "if (p && *p == 'a') {}" where the NULLness of p would be checked in the first expression before deferencing it in the second expression. Although not guaranteed, most C's stop evaluation once an ORing expression returns true from one of its expressions. Another potential surprise. ...Kenneth