Hide GCC warning "set but not used"?

jean picture jean · Nov 9, 2011 · Viewed 11.6k times · Source

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

Answer

cnicutar picture cnicutar · Nov 9, 2011

You can use this to shut it off:

(void)list;

Alternatively and less portably you can use __attribute__((unused)).