Given the following piece of code:
void test(int var)
{
Q_UNUSED(var);
#ifdef SOMETHING
printf("%d",var);
//do something else with var...
#endif
}
Would the Q_UNUSED
macro have any effect if I actually use the 'var' variable in some scenario (like in the example above), or it has no effect at all when I suppress compiler warnings for unused variables?
So far I observe it has no effect, but I would like to make sure.
No in many cases (e.g. just passing a simple variable to the macro). The definition is inside qglobal.h
:
# define Q_UNUSED(x) (void)x;
To disable unused variable warnings. You can use the variable after this macro without any problem.
However, if you pass an expression or something else to the macro and the compiler has to evaluate the expression it may has side effects† .