cgccpragma

How do I tell gcc to shut up about forward declaring struct inside parameter list?


#pragma GCC diagnostic push
#pragma GCC diagnostic ignore ???
int fstat(int handle, struct stat *statbuf); 
/* to get struct stat, #include <asm/stat.h> */
#pragma GCC diagnostic pop

I've gotten most of the way there, but in order to fill out the ignore pragma I need to know what to put there instead of ???.

This file just declares the asm stubs. Most users of this header file won't care about struct stat but one does. I will be disappointed if I have to make another header file for one line of declaration.


Solution

  • Without a prior declaration of struct stat, the given function declaration declares this struct type inside of the parameter list, and this declaration isn't visible outside the declaration, hence the error.

    Rather than added compiler specific flags to ignore the error, declare the struct outside of the declaration.

    struct stat;
    int fstat(int handle, struct stat *statbuf); 
    

    Since you're not actually using struct stat, you only need the declaration.