September 3, 2010
Hello-
gbulmer, thanks for the explanation. It makes complete sense that the value of int counter1
increments and eventually overflows to -3276X (I always forget the lower boundary value) BEFORE it is promoted to type long
and compared to limit
.
Yes, floating point calculations are subject to "rounding" errors. However, I feel it should not make a difference if a loop repeats 1000X or just 1X. If the loop is empty I think it should be removed by the compiler. Maybe the compiler authors have a reason for this feature.
Perhaps it is a simple way to measure of the speed of variable promotion! I am still surprised that in my sample code the empty loops using a limit of type float require more than 0 ms to execute.
I just thought of those examples of "bad" code where a programmer crams a lot unreadable code into the "test" expression of a FOR loop. Perhaps this is another reason to use just WHILE loops.
http://forums.leaflabs.com/topic.php?id=117#post-947
I guess I just answered my own question about the execution times of empty loops.
Thanks!
Stephen from NYC