This is the mail archive of the gcc-help@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]

Empty statement warning!


I'm sometimes doing the obvious mistake of adding a ";" after an if-statement.

if (<expression>);
  DoSomething();

This error sometimes causes weird behaviour of the program, and are hard to spot in the code.

I once read a recommendation that you should always add curly braces, even if for single statement blocks:

if (<expression>);
{
  DoSomething();
}

...as this would normally cause a good compiler to issue a warning.

But, using XCode on Mac (built on top of  GCC) I'm not warned for these errors, and I can't find an option in Xcode to enable such a warning. 

Is there another way to make gcc issue a warning for empty statements such as the one above (I know it's legal C / C++ code, but it's use is fairly narrow I would say).

Agnar

--
Agnar Renolen
eMap as (www.emap.no)


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