gcc unused attribute

07 Mar 2012

Dusting off my C skills and wanted to silence some benign used parameter warnings

warning: unused parameter ‘len’ [-Wunused-parameter]

Props to Martin Pool's blog for this nice macro:

#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

Use it as such:

int foobar(int a, int UNUSED(b))

It's nothing fancy or unique or even not commonly known, but I had to look it up. And so I'm giving Martin some SEO love.