c - why do I have to declare an irrelevant struct file_handle variable before I can use that type? -


following documentation linux open_by_handle_at() :

http://man7.org/linux/man-pages/man2/open_by_handle_at.2.html

i write c file:

#define _gnu_source #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h>  typedef void (*foobar) (struct file_handle *); 

but compiles ominous warning:

>gcc -c foobar.c warning: ‘struct file_handle’ declared inside parameter list 

if add irrelevant declaration in between:

#define _gnu_source #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h>  struct file_handle *junk;  typedef void (*foobar) (struct file_handle *); 

then compiles without warning. why warning??

you haven't declared struct file_handleanywhere in advance. compiler sees struct file_handle in above function definitions first time ever. in each case declaration of struct file_handle has block scope, i.e. local corresponding function.

add below structure before function.

 struct file_handle {                    unsigned int  handle_bytes;   /* size of f_handle [in, out] */                    int           handle_type;    /* handle type [out] */                    unsigned char f_handle[0];    /* file identifier (sized                                                     caller) [out] */                }; 

higher-level language lets place declarations/definitions pretty anywhere (such c++ or python), unfortunately, c compiled top-to-bottom


Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

Kivy: Swiping (Carousel & ScreenManager) -