Behold, my aclocal file (just put ENABLE_WARNINGS in configure.in and configure with --enable-warnings, or --enable-warnings=-Werror or whatever). If you're not using autotools, then you're PROBABLY using something inferior. Autotools sucks really hard, but still manages to suck less than SCons, Jam, CMake, or your favorite IDE.
AC_DEFUN([ENABLE_WARNINGS],[
AC_ARG_ENABLE(warnings,
[ --enable-warnings enable warnings for GCC ],
[enable_warnings=$enableval], [warnings=no])
if test "x$enable_warnings" != xno ; then
[warning_cflags="-Wall -Wextra -Wshadow -Wpointer-arith -Wbad-function-cast -Wcast-align -Wwrite-strings -Wstrict-prototypes -Wmissing-prototypes -Wnested-externs -Wchar-subscripts -Wredundant-decls -pedantic"]
if test "x$enable_warnings" != xyes ; then
[warning_cflags="$warning_cflags $enable_warnings"]
fi
fi
AC_SUBST([warning_cflags])
])
The "-Wshadow" can be a bitch, I have to rename variables e.g. "index" because there is a standard library function named "index".
I used to use "-Wno-unused-parameter" but I turned it on and it caught some bugs so I leave it on now, and stick these in my code:
int always_returns_three(int x)
{
(void)x;
return 3;
}
It's ugly but my code DOES have less bugs now.
As an alternative, plug in "clang" for a bit. It might spit out a bunch of new warnings, they'll often be pretty nice.
Name:
Anonymous2010-08-30 15:57
>>20
As a quick addendum, don't put "-W" options in CFLAGS, put them in a separate variable and then add that variable to AM_CFLAGS in Makefile.am. If you put them in CFLAGS, your configuration script might break, or fail to detect certain libraries that are installed.
>>20
Yeah, the problem with things like SCons and CMake is that the developers of these tools never really have experienced the need to have full control over the build process. They're lazy developers who don't care about actual REAL WORLD use cases.
Name:
Anonymous2010-08-30 21:26
>>22
You don't have full control over the build process until you've written your makefiles and configure script by hand.