I want to do a function to get a pointer on a struct. I done this :
void *getTokenList() {
static t_token *list;
return &list;
}
At compilation, I have this warning :
warning: variable ‘list’ set but not used [-Wunused-but-set-variable]
Is it possible to disable this warning for this function (only this one), or put an GCC attribute on this variable to hide this warning?
I had put #pragma GCC diagnostic ignored "-Wunused-but-set-variable"
in top of my file but I want to hide this warning ONLY for this variable in this function.
Thanks, Jean
To answer your question about disabling specific warnings in GCC, you can enable specific warnings in GCC with -Wxxxx and disable them with -Wno-xxxx. From the GCC Warning Options: You can request many specific warnings with options beginning -W , for example -Wimplicit to request warnings on implicit declarations.
variable was set but never used. This means you declared a variable, set its value, but never used it beyond setting its value.
In GCC, you can label the parameter with the unused attribute. This attribute, attached to a variable, means that the variable is meant to be possibly unused. GCC will not produce a warning for this variable.
This warning was a bug in gcc. The warning, introduced in version 4.6, can easy be disabled as explained in other answers, but it should be noted that current versions of gcc do not produce the warning.
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