Archive for December, 2008

Useful GCC-only trick: warn if return value is unused

Sunday, December 14th, 2008

So I found this useful thing that you can add to your functions on GCC compilers… basically, you add an attribute to the end of the function definition and GCC will warn anytime that function is called and the return value isn’t used. Ubuntu 8.10 has enabled this for a *ton* of system calls, and its pretty useful (except when you’re just trying to do something without bothering with error checking). Of course if you don’t like -Wall then you won’t like this either…

#ifdef __GNUC__
    #define WARN_IF_UNUSED __attribute__ ((warn_unused_result))
#else
    #define WARN_IF_UNUSED
#endif

int some_function() WARN_IF_UNUSED;