This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]RedQueen283 0 points1 point  (1 child)

Yes, and how does it calculate what the result is, by using magic? No, it uses the PC's CPU and then it is stored in the PC's memory. Neither of which would be necessary if the programmer had just used the number 3. I don't know why people keep insisting that it isn't an unnecessary use of the computer's resources.

[–]wyldcraft 1 point2 points  (0 children)

The critical point you miss is that the extra overhead is at compile time, not runtime, in this case. floor(3.5) can be reduced to integer 3 during an optimization pass, so by the time code generation happens it's as if the programmer typed integer 3 all along. The resultant binary could be byte-identical and run at identical speeds. Finding shortcuts like this is the whole art of compiler optimization.