Empty statement warning!

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux