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: Douglas Dotson
Subject: RE: [avr-gcc-list] Feature request - compiler warning for "if" stmts that do nothing
Date: Mon, 13 Dec 2004 15:34:16 -0800 (PST)

--- Dave Hylands <address@hidden> wrote:

> > > A feature I'm requesting is that the compiler
> generate a warning for
> > > control statements that don't do anything.
> > 
> > -Wextra?
> > 
> > According to the man page:
> > 
> >  o   An empty body occurs in an if or else
> statement.
> > 
> > I'd assume this to be warned.
> 
> Hey - that's pretty close.
> 
> It triggers on the original posters original
> request:
> 
>       if ( condition );
>       {
>               ... Do something ...
>       }
> 
> x.c:8: warning: empty body in an if-statement
> 
> And doesn't trigger on my example: if
> (condition);else{...do
> something...}

That's because an empty then-part with a non-empty
else-part can be useful. I personally find such usage 
a bit annoying but sometimes it makes the intent
clearer rather then testing for the inverse condition.

> It still doesn't warn about while/for loops that are
> similar:
> 
>       while ( conition );
>       {
>               ... Do something ...
>       }

Quite alot of things can be done in while loops
that do not have bodies. Things like:

 while (*p++ = *q++);

> And
> 
>       for (i=0;i<10;i++);
>       {
>               ... Do something ...
>       }

Same thing applies as with the while. The for 
statement is so versatile that many things can be
done without a body.
 
> So it's definitely a step in the right direction.

Welcome to the world of C. There are some nice LINT 
type programs that can help with this, but normally
they generate so many warnings that it is hard to
separate the real problems from the aberations. Best
solution is to develop good programming skills that
avoid the typical pitfalls.
 
> --
> Dave Hylands
> Vancouver, BC, Canada
> http://www.DaveHylands.com/ 
> 
> 
> _______________________________________________
> avr-gcc-list mailing list
> address@hidden
> http://www.avr1.org/mailman/listinfo/avr-gcc-list
> 



reply via email to

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