How to suppress warnings about unused variables in C ++?

How can I suppress the warning compiler generating unused variables in a C ++ program?

I am using the g ++ compiler

+6
source share
3 answers

Compile with the -Wno-unused-variable option.

See the GCC documentation of warning parameters for more information.

The -Wno-__ options disable the options set by -W__ . Here we turn -Wunused-variable .

In addition, you can apply __attribute__((unused)) to a variable (or function, etc.) to suppress this warning in each case. Thanks to Jesse Good for this.

+7
source

Put the cast in void:

 int unused; (void)unused; 
+10
source

To remove these warnings, I create a macro that can be used throughout my project:

 #define UNUSED(x) (void)(x) 
+2
source

Source: https://habr.com/ru/post/922252/


All Articles