if() and trailing ;

Gabriel Dos Reis gdr@integrable-solutions.net
Tue Aug 1 14:54:00 GMT 2006


"Denis Vlasenko" <vda.linux@googlemail.com> writes:

| On 7/30/06, Joe Buck <Joe.Buck@synopsys.com> wrote:
| > On Sat, Jul 29, 2006 at 07:33:03PM -0400, Simon Boulet wrote:
| > > After a couple hours debugging code, I figured our an if() somewhere
| > > had a trailing ;  like this:
| > >
| > >                 if (memcmp(p, COMMUNITY, strlen(COMMUNITY)) != 0);
| > >                         continue; /* failed */
| > >
| > > The code above will always reach "continue" even when memcmp() == 0.
| > >
| > > I was surprised to see gcc doesn't report anything, I would expect a
| > > "statement has no effect" warning.
| >
| > But it is common to have an empty action on a condition.  You'll often
| > see code like
| >
| >     if (condition)
| >         /* nothing */;
| >
| > or more usually
| >
| >     if (condition) {
| >        /* nothing */;
| 
| if()
|     (void)0; /* do nothing */
| 
| will make you happy.

No, I'm not.  I find it Very Silly.

-- Gaby



More information about the Gcc mailing list