&& and || *are* left to right

BALDWIN mike at whuxl.UUCP
Thu Oct 31 04:34:09 AEST 1985


>                                                           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]

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



More information about the Comp.lang.c mailing list