Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hide GCC warning "set but not used"?

Tags:

c

gcc

warnings

hide

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

like image 379
jean Avatar asked Nov 09 '11 20:11

jean


People also ask

How do I get rid of GCC warnings?

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.

What does variable set but not used mean?

variable was set but never used. This means you declared a variable, set its value, but never used it beyond setting its value.

What is unused parameter in C?

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.


1 Answers

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.

like image 144
chqrlie Avatar answered Sep 27 '22 19:09

chqrlie