Avoiding "unused variable" warnings
I think I have seen it somewhere but forgot.
Is it possible to create a noop macro that makes compiler believe macro arguments are used? I mean the case of debug macro that for debug off is redefined as something like do { } while(0) but then if arguments are used for debugging purposes only compiler emits warning. Some people do not like it :)
TIA
-andrey
Quoted 3 lines · Andrey Borzenkov
I think I have seen it somewhere but forgot.
Is it possible to create a noop macro that makes compiler believe macro arguments are used? I mean the case of debug macro that for debug off is redefined as something like do { } while(0) but then if arguments are used for debugging purposes only compiler emits warning. Some people do not like it :)
No need for a macro, just do
(void) var_name;
It doesn't generate any code, and it shuts up the compiler.
Jeff
Quoted 5 lines · Jeff Garzik
No need for a macro, just do
(void) var_name;It doesn't generate any code, and it shuts up the compiler.
It may do. The proper gcc thing is attribute unused. Both are dangerous as they hide when the variable becomes really unused
Hi,
Quoted 8 lines · Alan Cox
Quoted 5 lines
No need for a macro, just do
(void) var_name;It doesn't generate any code, and it shuts up the compiler.
It may do. The proper gcc thing is attribute unused. Both are dangerous as they hide when the variable becomes really unused
Function like macros, which throw away their arguments, can be dangerous. I had a funny bug like this:
kunmap(*pagep++);
bye, Roman