C Style

Michael Laufer mlaufer at bbncct.ARPA
Fri Nov 1 08:47:14 AEST 1985


Wait just one minute there.  Dan Levy (..!ihnp4!ttrdc!levy) writes :

>>Scott's example done the RIGHT (i.e. my :-))  way:
>>	 for(i = 0; i < 100; i++) {
>>		 if(f1(x) == OK &&
>>		    f2(x) == OK &&
>>		    f3(x) == OK &&
>>		    f4(x) == OK &&
>>		    f5(x) == OK	   ) {
>>			 result[i] = 0;
>>		 }
>>		 else {
>>			 result[i] = function6(x);
>>		 }
>>	 }
>..........  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).

I hope this is not the case or I know a lot of code that will self destruct.

In Harbison & Steele _A_C_Reference_Manual_ on page 181 :

....the logical operator '&&' guarantees left-to-right conditional evaluation.

Any compilers that do not work this way cannot really call themselves 'C'
compilers.  What does the ANSI standard say about this?

				Michael Laufer
				mlaufer at bbn-unix.arpa



More information about the Comp.lang.c mailing list