How can one suppress warnings compiler generates about unused variables in a c++ program?
I am using g++ compiler
Put in a cast to void:
int unused;
(void)unused;
Compile with the -Wno-unused-variable
option.
See the GCC documentation on Warning Options for more information.
The -Wno-__
options turn off the options set by -W__
. Here we are turning off -Wunused-variable
.
Also, you can apply the __attribute__((unused))
to the variable (or function, etc.) to suppress this warning on a case-by-case basis. Thanks Jesse Good for mentioning this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With