Reputation: 470
what does this macro mean ? I just find the following macro in source files:
#define UNUSED(x) ((x)=(x))
Upvotes: 7
Views: 4072
Reputation: 64223
It silence the compiler from complaining that a variable is not used.
Other ways to do it :
void foo( int )
void foo( int /* value */ )
void foo( int value ){ UNUSED(value); }
Upvotes: 2
Reputation: 124712
It is probably there to suppress compiler warnings of unused variables/arguments to functions. You could also use this:
// C++ only
void some_func(int /*x*/)
Or
// C and C++
void some_func(int x)
{
(void)x;
}
Or your compiler may support a flag to do so, but these are portable and won't skip over valid warnings.
Upvotes: 9
Reputation: 14067
Some compilers issue a warning about unused variables - variables that are defined but never referenced. Sometimes you have code that references a variable only under some conditional ifdefs (only on some platforms or only in debug) and it is inconvenient to duplicate those conditions at the point the variable is defined. A macro like this can be used to suppress the unused variable warning in such cases.
Upvotes: 2
Reputation: 70951
Use it to get rid of any compiler warning referring an unused variable.
Upvotes: 5