/* * Since I wrote on the board during the midterm that * a < b && c * should be evaluatd as * (a < b) && c * regardless of what it actually is, you should have followed the given * instructions. * * For the doubting thomases in the class, who claim that * a < b && c should be evaluated as either * (1) a < (b && c) * (2) (a < b) && (a < c) * here is a trivial program that should convince you which interpretation * is right. * * You should complain to whomever taught you otherwise. * * This program actually brings us to an important technique that all * reasonable compilers employ to optimize code, a technique that you should * be able to use as well when writing assembly: constant expression * evaluation/propagation and dead-code elimination. When this code is * compiled, the compiler can fully evaluate the constant expression used * in the condition; since the compiler knows that the else branch will never * be executed, it is eliminated from the generated code. * * Try the following: * * % cc -S -O precedence.c * * which should generate an assembly language listing in the file * precedence.s -- look through that: the code will be just a straight * line sequence with a single call to printf. (On the SPARCs, of course, * you'll be seeing SPARC assembly language with which you are unfamiliar, * but you should be able to get the gist of what's going on.) * The -O flag turns on compiler optimizations. See what happens when * you omit it. */ void main(void) { if (3 < 4 && 1) { printf("Bennet is right. Does this convince you?\n"); } else { printf("Bennet is wrong.\n"); } }