Re: Why INFINITE loop in a thread occupy so much CPU time??
- From: Joseph M. Newcomer <newcomer@xxxxxxxxxxxx>
- Date: Fri, 16 Nov 2007 23:10:12 -0500
I know that. Back when I was a C programmer in the early 1980s, I defined
boolean.h
typedef int boolean;
#define true 1
#define false 0
Using integer types instead of a boolean type is essentially slopping programming. This
is in the same class as people writing
int flag;
and then writting
flag = 1;
or
flag = 0;
to change a boolean value. It is habit that too many bad C programmers seem to develop,
since they learned C from K&R first edition. Since I learned to program in real languages
that had a boolean type, I decided that using integers to represent boolean values was a
really stupid idea. I wrote a few C programs in the 1970s, but decided the language was
apalling. K&R C really was an apalling language. ANSI C was the first respectable
instance of the language, and C++ is of course much better. But I find programmers using
the antiquated concept that integers should be used to represent boolean values even
today.
I consider any compiler that diagnoses while(TRUE) to be worthy of a warning to be a
compiler that does not understand reality.
joe
On Fri, 16 Nov 2007 05:34:47 -0500, David Wilkinson <no-reply@xxxxxxxxxxxx> wrote:
Joseph M. Newcomer wrote:Joseph M. Newcomer [MVP]
Perhaps because you asked it to? If you write a computation that consumes all the CPU, it
is going to, guess what, consume all the CPU! And that's what you've written! So
presumably you WANT to consume 100% of the available CPU time.
I have no idea what while(1) means anyway. while(TRUE) makes sense; while(true) makes
sense. What's an integer got to do with it?
Joe:
Well, while(1) and while(TRUE) are in fact the same thing. while(1) is
often used in C where there is no bool type.
I agree that while(true) is preferred, but all these constructs produce
warnings in recent VC versions at level 4 (at least in C++ mode), and
the preferred usage is for(;;). I find this ugly, but have started using
it since I started compiling at level 4.
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
.
- Follow-Ups:
- References:
- Why INFINITE loop in a thread occupy so much CPU time??
- From: lostlander
- Re: Why INFINITE loop in a thread occupy so much CPU time??
- From: Joseph M . Newcomer
- Re: Why INFINITE loop in a thread occupy so much CPU time??
- From: David Wilkinson
- Why INFINITE loop in a thread occupy so much CPU time??
- Prev by Date: Re: Drive letter and current running OS
- Next by Date: Re: Multilanguage support for CEdit
- Previous by thread: Re: Why INFINITE loop in a thread occupy so much CPU time??
- Next by thread: Re: Why INFINITE loop in a thread occupy so much CPU time??
- Index(es):
Relevant Pages
|