Search code examples
cgccwarningshide

Hide GCC warning "set but not used"?


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


Solution

  • You can use this to shut it off:

    (void)list;
    

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