Empty statement warning!

Agnar Renolen agnar.renolen@emap.no
Sat Nov 26 05:19:00 GMT 2011


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)



More information about the Gcc-help mailing list