gustaf gustaf - 1 year ago 46
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 Source

Found an article that explains UNUSED. Interesting that the author also mangles the unused variable name so you can't inadvertently use it in the future.


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

void dcc_mon_siginfo_handler(int UNUSED(whatsig))