Re: Why INFINITE loop in a thread occupy so much CPU time??
On Fri, 16 Nov 2007 23:10:12 -0500, Joseph M. Newcomer <newcomer@flounder.com>
wrote:
I consider any compiler that diagnoses while(TRUE) to be worthy of a warning to be a
compiler that does not understand reality.
joe
Interesting...
int main(void)
{
while(true);
return 0;
}
"warning C4127: conditional expression is constant"
Affected: All versions of Microsoft VC++ since I can remember and proven on VC++
6.0 and 2005.
Constructs like this don't emit diagnostics at /W4:
bool forever = true;
int main(void)
{
while(forever);
return 0;
}
One can write 'bool' in C++ but not C. On some implementations bool equated to
int so it's a distinction without a difference... unless you are dealing with
legacy DLL's:
__________________
Microsoft Specific
In Visual C++4.2, the Standard C++ header files contained a typedef that equated
bool with int. In Visual C++ 5.0 and later, bool is implemented as a built-in
type with a size of 1 byte. That means that for Visual C++ 4.2, a call of
sizeof(bool) yields 4, while in Visual C++ 5.0 and later, the same call yields
1. This can cause memory corruption problems if you have defined structure
members of type bool in Visual C++ 4.2 and are mixing object files (OBJ) and/or
DLLs built with the 4.2 and 5.0 or later compilers.
END Microsoft Specific
_________________
Use of while(1) is ancient in C and K&R NEVER wrote while(1) and in fact wrote
for(;;) as an infinite loop (page 60 of 1st Ed.) and stated explicitly on page
60 that use of 'for' in loop control was preferable to 'while' in most cases.
Programmers who write while(1) demonstrate profound ignorance of the C language
and loop constructs.