| This reminds me of something my assembly instructor said in class once (paraphrased): "Once, I was interested in finding out how a C compiler would handle the div instruction. So, I opened up my editor, and wrote this C program: void main () {
printf("%f", 14.0 / 3.0);
}
I compiled it, and took a look at the generated assembly. How many div instructions do you think it used?[Various guesses, mostly "one."] The correct answer is "zero." The compiler figured it out at compile time, and put a constant in instead. So, I decided to put it in a function: float divide (float a, float b) {
return a / b;
}
void main () {
printf("%f", divide(a, b));
}
Guess what happened next.[Various guesses.] The f--king compiler optimized it out again!" |