Re: Why INFINITE loop in a thread occupy so much CPU time??



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:
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.
Joseph M. Newcomer [MVP]
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
.



Relevant Pages

  • Re: Why INFINITE loop in a thread occupy so much CPU time??
    ... The language was Bliss, ... lived for many years) and passing variables, boolean especially, from one ... I heard some time ago about a compiler which IIRC ... It is habit that too many bad C programmers ...
    (microsoft.public.vc.mfc)
  • Re: Bob P. and Roger G. --> IF(and(...IF(OR( vs. IF(Boolean
    ... We didn't start using Excel 'til about 92? ... I say only the *well-trained* programmers. ... having a job title of "programmer" but have no idea of Boolean. ... SUMPRODUCT and I am learning to use Boolean outside of SUMPRODUCT. ...
    (microsoft.public.excel.worksheet.functions)
  • Re: Bob P. and Roger G. --> IF(and(...IF(OR( vs. IF(Boolean
    ... They are about to switch to Excel finally. ... When I talked about using Boolean and taking risk, ... I say only the *well-trained* programmers. ... SUMPRODUCT and I am learning to use Boolean outside of SUMPRODUCT. ...
    (microsoft.public.excel.worksheet.functions)
  • Re: First C Program, Problems getting serial data
    ... only for values that really are boolean. ... strcmp() gives a consistent ordering of string values. ... There is an entire generation of programmers who were taught ... I spent a lot of my early career as an assembler programmer, and comparing strings I would naturally end up with something that behaved like strcmp since comparing two bytes gave that information on the processors I was using. ...
    (comp.lang.c)
  • Re: Negation of boolean
    ... Java has the values true and false at the source code level. ... DataOutputStream of a boolean you get the numbers 1 and 0, ... Java and C programmers tend to think of boolean assignment as less ...
    (comp.lang.java.help)