Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I suppress "unused parameter" warnings in C?

Tags:

c

gcc

gcc-warning

For instance:

Bool NullFunc(const struct timespec *when, const char *who) {    return TRUE; } 

In C++ I was able to put a /*...*/ comment around the parameters. But not in C of course, where it gives me the error:

error: parameter name omitted

like image 849
nixgadget Avatar asked Aug 30 '10 09:08

nixgadget


People also ask

How do I turn off unused variable warning?

By default, the compiler does not warn about unused variables. Use -Wunused-variable to enable this warning specifically, or use an encompassing -W value such as -Weverything . The __attribute__((unused)) attribute can be used to warn about most unused variables, but suppress warnings for a specific set of variables.

What is unused parameter?

Reports the parameters that are considered unused in the following cases: The parameter is passed by value, and the value is not used anywhere or is overwritten immediately. The parameter is passed by reference, and the reference is not used anywhere or is overwritten immediately.

What is unused C?

__attribute__((unused)) function attribute The unused function attribute prevents the compiler from generating warnings if the function is not referenced. This does not change the behavior of the unused function removal process.

How do you fix unused variables in Python?

To suppress the warning, one can simply name the variable with an underscore ('_') alone. Python treats it as an unused variable and ignores it without giving the warning message.


1 Answers

I usually write a macro like this:

#define UNUSED(x) (void)(x) 

You can use this macro for all your unused parameters. (Note that this works on any compiler.)

For example:

void f(int x) {     UNUSED(x);     ... } 
like image 189
mtvec Avatar answered Sep 23 '22 10:09

mtvec