avr-gcc-list
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [avr-gcc-list] Feature request - compiler warning for "if" stmts tha


From: Bob Paddock
Subject: Re: [avr-gcc-list] Feature request - compiler warning for "if" stmts that do nothing
Date: Mon, 20 Dec 2004 07:30:39 -0500
User-agent: KMail/1.7.1

On Monday 13 December 2004 05:06 pm, Curtis Maloney wrote:

> >  while ((SPSR & (1 << SPIF)) == 0)
> >   ;

Lint can be made to not complain about that because it is a common use, 
but it will still complain about:

while ((SPSR & (1 << SPIF)) == 0);

> I'd rather have a few warnings on things I know are ok _this time_,

Warnings are *ALWAYS* bad.  Think of the next guy that has to work on the 
code, he is not going to know which warnings are 'ok' and which are real.
Leaving warnings in code leads to complacency in ignoring warnings,
not a road to start down.

> the time when you accidently put = instead of ==, but some times it's what

If you want to save yourself debugging time get in the habit of putting
the constants on the left:

while (0 == (SPSR & (1 << SPIF))
 ;

while ((SPSR & (1 << SPIF)) = 0)
 ;
would be an error that some compilers say nothing about.

The compiler will always barf if the constant is on the left because
you can not assign a value to a constant.


-- 
                          http://www.softwaresafety.net/
 http://www.unusualresearch.com/ http://www.bpaddock.com/



reply via email to

[Prev in Thread] Current Thread [Next in Thread]