gustaf gustaf - 1 month ago 5
C Question

What is the best way to supress "Unused variable x"-warning

What is the best/neatest way to suppress a compiler (in this case gcc) like "Unused variable x"-warning?

I don't want to give any certain flags to gcc to remove all these warnings, just for special cases.

Answer

Found an article http://sourcefrog.net/weblog/software/languages/C/unused.html that explains UNUSED. Interesting that the author also mangles the unused variable name so you can't inadvertently use it in the future.

Excerpt:

#ifdef UNUSED
#elif defined(__GNUC__)
# define UNUSED(x) UNUSED_ ## x __attribute__((unused))
#elif defined(__LCLINT__)
# define UNUSED(x) /*@unused@*/ x
#else
# define UNUSED(x) x
#endif

void dcc_mon_siginfo_handler(int UNUSED(whatsig))