Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PC Lint while(TRUE) vs for(;;)

I'm using PC Lint for the first time. I was "linting" my code, when PC Lint warns me about my while(TRUE).

This is what it says:

716: while(1) ... -- A construct of the form while(1) ... was found.

Whereas this represents a constant in a context expecting a Boolean, it may reflect a programming policy whereby infinite loops are prefixed with this construct. Hence it is given a separate number and has been placed in the informational category. The more conventional form of infinite loop prefix is for(;;).

I didn't understand this statement. Can anyone help me to understand it?

like image 786
Daniel Grillo Avatar asked Sep 23 '11 11:09

Daniel Grillo


1 Answers

The text says that although while(TRUE) (which gets preprocessed into while(1)) is a perfectly valid infinite loop, the more conventional form of writing an infinite loop is

for(;;)
{
   ...
} 

because it doesn't use any values at all and therefore is less error-prone.

like image 196
Armen Tsirunyan Avatar answered Sep 16 '22 18:09

Armen Tsirunyan