Erik de Castro Lopo
2007-Sep-12 04:13 UTC
[Flac-dev] Two GCC warnings flags you should enable ASAP
Josh, There are two GCC warning flags you should enable for all the C code ASAP. From the gcc man page: -Wmissing-prototypes (C only) Warn if a global function is defined without a previous prototype declaration. This warning is issued even if the definition itself provides a prototype. The aim is to detect global functions that fail to be declared in header files. -Wstrict-prototypes (C only) Warn if a function is declared or defined without specifying the argument types. (An old-style function definition is permitted without a warning if preceded by a declaration which specifies the argument types.) Currently in the file src/share/utf8/charset.c you use the new allocation functions without including "include/share/alloc.h". The first warning flag above would catch this issue. The second warning flag will catch things like old-style K&R function definitions which were obsoleted by the 18 year old 1989 C standard :-). These two warning flags have been available at least since gcc-2.95. All the 3 and 4 series gcc compilers accept them. Cheers, Erik -- ----------------------------------------------------------------- Erik de Castro Lopo ----------------------------------------------------------------- "When exported to Muslim lands, various aspects of Western pop culture must be modified in order to accommodate Muslim sensibilities. When Muslims come West, various aspects of Western pop culture must be modified in order to accommodate Muslim sensibilities." -- http://www.jihadwatch.org/dhimmiwatch/archives/008623.php
Erik de Castro Lopo
2007-Sep-12 04:36 UTC
[Flac-dev] Two GCC warnings flags you should enable ASAP
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
Erik de Castro Lopo
2007-Sep-12 07:05 UTC
[Flac-dev] Two GCC warnings flags you should enable ASAP
Erik de Castro Lopo wrote:> 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.I've done some more investigation of this issue. It turns out that the dangerous scenario I outline in my previous email is actually caught by the -Wall flag which you already use. The -Wmissing-prototype warning flag catches a related (and even more subtle) problem which the -Wall and -W/-Wextra flags ignore. Consider three files: first.c second.c second.h The file first.c includes second.h which defines function X, with the implementation of function X being in second.c. Now consider the case where second.c does not include second.h and the implementation in second.c does not match the prototype in second.h. In this case, first.c which includes second.h expects function X to behave as it was specified in the header, but the implementation in second.c doesn't match. This is a recipie for pain very similar to what I describe in my previous email. However, like the previous problem, the C++ linker would catch the mis-match. Erik -- ----------------------------------------------------------------- Erik de Castro Lopo ----------------------------------------------------------------- "The X-files is too optimistic. The truth is not out there." -- Anthony Ord
Josh Coalson
2007-Sep-12 17:49 UTC
[Flac-dev] Two GCC warnings flags you should enable ASAP
I'll add these, I think they didn't get in with your previous patch because I withheld a part of it for some other reason... --- Erik de Castro Lopo <erikd-flac@mega-nerd.com> wrote:> Josh, > > There are two GCC warning flags you should enable for all the > C code ASAP. From the gcc man page: > > -Wmissing-prototypes (C only) > Warn if a global function is defined without a previous prototype > declaration. This warning is issued even if the definition > itself > provides a prototype. The aim is to detect global functions that > > fail to be declared in header files. > > -Wstrict-prototypes (C only) > Warn if a function is declared or defined without specifying the > argument types. (An old-style function definition is permitted > without a warning if preceded by a declaration which specifies > the > argument types.) > > Currently in the file src/share/utf8/charset.c you use the new > allocation > functions without including "include/share/alloc.h". The first > warning > flag above would catch this issue. The second warning flag will catch > things like old-style K&R function definitions which were obsoleted > by the 18 year old 1989 C standard :-). > > These two warning flags have been available at least since gcc-2.95. > All the 3 and 4 series gcc compilers accept them. > > Cheers, > Erik > -- > ----------------------------------------------------------------- > Erik de Castro Lopo > ----------------------------------------------------------------- > "When exported to Muslim lands, various aspects of Western pop > culture must be modified in order to accommodate Muslim > sensibilities. > When Muslims come West, various aspects of Western pop culture must > be modified in order to accommodate Muslim sensibilities." > -- http://www.jihadwatch.org/dhimmiwatch/archives/008623.php > _______________________________________________ > Flac-dev mailing list > Flac-dev@xiph.org > http://lists.xiph.org/mailman/listinfo/flac-dev >____________________________________________________________________________________ Building a website is a piece of cake. Yahoo! Small Business gives you all the tools to get online. http://smallbusiness.yahoo.com/webhosting