Skip to contentSkip to conversation

Avoiding "unused variable" warnings

DISCUSSION Andrey Borzenkov 4 participants 4 messages Jul 13, 2003

lore
Share & tools
lore
#0 lore raw

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

#1 lore raw
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

#2 lore raw
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

#3 lore raw

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