[0] http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1124.pdf (See 6.8.5.3)
http://msdn.microsoft.com/en-us/library/6t66728h%28v=vs.80%2...
http://stackoverflow.com/questions/3490823/why-msvc-generate...
#define ever (;;)
for ever {...}
;-) for {
...
}http://stackoverflow.com/questions/885908/while-1-vs-for-is-...
for (;;);
is the same as
{ while (true) { ; ; } }
I originally asked this question cos it's used this way in first C program in the link. Bit of a tangent though :P
And to add oil to the fire, here are some even 'better' ways to do this:
do {
...
} while(1);
At least that fits the common macro pattern "do{...}while(0)" (http://stackoverflow.com/questions/257418/do-while-0-what-is...).Of course, all of these are inferior to:
considered:
...
goto considered;I prefer "for(;;)" because it is explicitly defined as an infinite loop, but "while(1)" needs an implicit cast of "1" to "true", and even then there's an implicit test for "true".
http://pubs.opengroup.org/onlinepubs/007904975/basedefs/stdb...
Edit: Of course I'm talking about C here. Also, I prefer for(;;) because it's an easy to recognize idiom that means "infinite loop."
I just did a quick check and gcc -S produces the same ASM output for both of them, which doesn't include any comparisons whatsoever, just a jmp. So both of them are really compiled to an actual infinite loop.
The good thing is modern compilers can evaluate a loop and if the break condition is constant it can just do an infinite loop without checking.