Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does Q_UNUSED have any side effects?

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.

like image 314
Ilya Kobelevskiy Avatar asked Oct 24 '13 21:10

Ilya Kobelevskiy


1 Answers

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.

like image 99
masoud Avatar answered Oct 06 '22 23:10

masoud