Both should be same if your code is optimized by compiler. To explain what I mean by optimization, here is a sample code written in MSVC 10:
int x = 0;
while(true) // for(;;)
{
x +=1;
printf("%d", x);
}
If you build it in Debug mode (without any optimization (/Od)) disassembly shows the clear difference. There is extra instructions for the true
condition inside while
.
while(true)
00D313A5 mov eax,1 //extra
00D313AA test eax,eax //extra
00D313AC je main+39h (0D313B9h) //extra
{
x +=1;
00D313AE mov eax,dword ptr [x]
00D313B1 add eax,1
00D313B4 mov dword ptr [x],eax
printf("%d", x);
...
}
00D313B7 jmp main+25h (0D313A5h)
for(;;)
{
x +=1;
00D213A5 mov eax,dword ptr [x]
00D213A8 add eax,1
00D213AB mov dword ptr [x],eax
printf("%d", x);
...
}
00D213AE jmp main+25h (0D213A5h)
However, if you build your code in Release mode (with default Maximize Speed (/O2)) you get same output for both. Both loops are reduced to one jump instruction.
for(;;)
{
x +=1;
01291010 inc esi
printf("%d", x);
...
}
0129101C jmp main+10h (1291010h)
while(true)
{
x +=1;
00311010 inc esi
printf("%d", x);
...
}
0031101C jmp main+10h (311010h)
Whichever you will use does not matter for a decent compiler with speed optimization is on.
TRUE
??? – AnTTRUE
have to do with C? The standard macro for true boolen result in C99 is stilltrue
. Where did theTRUE
come from? – AnT#define EVER ;;
has been used in IOCCC though.. :) – Roger Pate#define while(TRUE)
declaring a macro that takes one argument calledTRUE
that is never used, therefore turning every single while loop in your program in to an infinite loop? – AshleysBrainTRUE
comes from header files associated with Windows API. It is not related to VS 6.0 in any way. And, as I said before, it has nothing to do with either C or C++. In C++ the "true" literal is justtrue
(in VS 6.0 as well), in C89/90 there's no such thing at all, and in C99 it is macrotrue
. This applies to all C/C++ compilers. – AnT