News for hackers. Stuff that matters.
Re:The Beauty of Bresenham's Algorithm by nitrogen on Tuesday August 07, 2012 @09:11PM (#4353333)
Because while(1) still has a condition that is checked on every loop iteration when optimizations are disabled. for(;;) can be read as "forever".
Re:The Beauty of Bresenham's Algorithm by morsch on Tuesday August 07, 2012 @09:18PM (#4353356)
FWIW, GCC and Perl generate the same code for both.

http://stackoverflow.com/questions/885908/while-1-vs-for-is-...

Re:The Beauty of Bresenham's Algorithm by barbs on Tuesday August 07, 2012 @09:25PM (#4353380)
Interesting. Looks like they'd be the same performance wise, since

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

Re:The Beauty of Bresenham's Algorithm by WalterBright on Wednesday August 08, 2012 @12:47AM (#4353964)
That issue disappeared before the 1980's. Check your compiler.
Re:The Beauty of Bresenham's Algorithm by jejones3141 on Wednesday August 08, 2012 @12:11AM (#4353854)
Any compiler/interpreter worth its salt will notice when an expression being tested in a conditional is constant and generate code that doesn't actually test it at run time. for (;;) is arguably more "idiomatic" C, though.
Re:The Beauty of Bresenham's Algorithm by Someone on Wednesday August 08, 2012 @06:45AM (#4354874)
for(;;), being equivalent to for(;1;), also has that condition that has to be checked. So, it all boils down to how compilers treat the two.

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;
Re:The Beauty of Bresenham's Algorithm by FredBrach on Tuesday August 07, 2012 @09:21PM (#4353366)
I do doubt that even for a for(;;), a jmp (x86) is use instead of a conditional jump like jz.
Re:The Beauty of Bresenham's Algorithm by dbaupp on Wednesday August 08, 2012 @01:57AM (#4354165)
Compilers are smart! For common things like this, they will easily optimise away any conditional jumps.
Re:The Beauty of Bresenham's Algorithm by tsahyt on Wednesday August 08, 2012 @09:27AM (#4355377)
It is, you can easily check that yourself. for(;;) compiles to exactly one jmp in GCC (tested with gcc 4.7.0)