[Flac-dev] Two GCC warnings flags you should enable ASAP

Erik de Castro Lopo erikd-flac at mega-nerd.com
Wed Sep 12 04:36:12 PDT 2007


Erik de Castro Lopo wrote:

> There are two GCC warning flags you should enable for all the 
> C code ASAP.

Sorry, I don't want to seem too pushy on this issue, but I consider
-Wmissing-prototypes a really important issue. It bit me really
badly once and has been a hobby horse of mine ever since.

The reason its important is that in C (C++ is a different matter
which I'll explain later), if no prototype for a function is seen,
the compiler assumes that the caller will get the number, order
and type of the function arguments correct. However, if the caller
gets it wrong (or the function definition changes) really bad stuff
happens (ie really horrible, hard to track down bugs). In addition,
if you don't include the header, automake doesn't realise that the
caller depends on the header (and hence the function definition).

In C++ its a different matter. Because of function overloading, the
C++ linker does the checking of function arguments, order and count
and doesn't allow you to mess up. Thats why the -Wmissing-prototype
flag is C only.

Hope this helps.

Cheers,
Erik
-- 
-----------------------------------------------------------------
Erik de Castro Lopo
-----------------------------------------------------------------
"I don't think any MS Exec will ever die of old age. Satan
doesn't need the competition."
-- Digital Wokan on LinuxToday.com


More information about the Flac-dev mailing list