This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: if() and trailing ;


On Tuesday 01 August 2006 16:54, Gabriel Dos Reis wrote:
> "Denis Vlasenko" <vda.linux@googlemail.com> writes:
> | if()
> |     (void)0; /* do nothing */
> | 
> | will make you happy.
> 
> No, I'm not.  I find it Very Silly.

Do you prefer buggy code like this?

| > > 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.

We want gcc to warn about such cases (about empty if's, that is).
Thus we need to have non-empty statement in if() body, always.

Of course you do not write "if(expr) (void)0;" directly,
it's what compiler sees.

Usage is

#if ....
#define do_something() ((void)0)
#endif
...

    if(expr) do_something();
--
vda


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]