&& and || *are* left to right

Daniel R. Levy levy at ttrdc.UUCP
Thu Oct 31 11:55:19 AEST 1985


In article <757 at whuxl.UUCP>, mike at whuxl.UUCP (BALDWIN) writes:
>>                                                           The && operator
>> doesn't GUARANTEE the chronological order of evaluation is going to be left
>> to right, if you have a screwball compiler (though it most probably will be).
>>						[dan levy] (that's me)
>
>I have to disagree with this.  && and || are guaranteed to be left to right
>just as much as (1 && 1) is guaranteed to return true.  This is a very
>important feature of C and makes tests like
>	if (x != NULL && strcmp(x, "foo"))
>reasonable.  If there are compilers out there that don't do && and || left
>to right, then they are broken.  I'm not going to rewrite conditionals like
>that example (as nested ifs!) to accomodate *broken* compilers!
>	In C, && and || ARE GUARANTEED to be evaluated left to right!!
>						Michael Baldwin
>						{at&t}!whuxl!mike
I stand corrected.
-- 
 -------------------------------    Disclaimer:  The views contained herein are
|       dan levy | yvel nad      |  my own and are not at all those of my em-
|         an engihacker @        |  ployer or the administrator of any computer
| at&t computer systems division |  upon which I may hack.
|        skokie, illinois        |
 --------------------------------   Path: ..!ihnp4!ttrdc!levy



More information about the Comp.lang.c mailing list