• Advertisement
Sign in to follow this  

cryptic gcc warning: function ponter typedef w/ struct pointer argument

This topic is 1415 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have a struct with a function pointer in it.  This compiles fine:

typedef struct gx_quadpatch_s
{
    gx_vbuffer_t* vb;
    struct gx_quadpatch_s* children[4];
    struct gx_quadpatch_s* parent;

    //...

    void (*detailer)(struct gx_quadpatch_s* dest, struct gx_quadpatch_s* source, int a_start, int a_end, int b_start, int b_end);



} gx_quadpatch_t ;

I wanted a pretty typedef for the function type:

 

typedef     void (*gx_quadpatch_detailer_f)(     struct gx_quadpatch_s* dest, struct gx_quadpatch_s* source, int a_start, int a_end, int b_start, int b_end);


typedef struct gx_quadpatch_s
{
    gx_vbuffer_t* vb;
    struct gx_quadpatch_s* children[4];
    struct gx_quadpatch_s* parent;

    //...

    gx_quadpatch_detailer_f detailer;

} gx_quadpatch_t ;

GCC gives this warning:
 

In file included from gx_quadpatch.c:18:0:
../graphics/gx_quadpatch.h:5:80: warning: 'struct gx_quadpatch_s' declared inside parameter list [enabled by default]
 typedef  void (*gx_quadpatch_detailer_f)(  struct gx_quadpatch_s* dest, struct gx_quadpatch_s* source, int a_start, int a_end, int b_start, int b_end);
                                                                                ^
../graphics/gx_quadpatch.h:5:80: warning: its scope is only this definition or declaration, which is probably not what you want [enabled by default]

This suggests I need to declare the struct quadpatch_s definition before the gx_quadpatch_detailer_f.  Circular dependency.  Not sure how to break it.

 

Usually if I have an interdependency between structs, I can do this:

typedef struct foo_s
{
    struct bar_s* my_bar;

} foo_t;

typedef struct bar_s
{
   struct foo_s* my_foo;
} bar_t;

After that, I can refer them at foo_t and bar_t.  In its allowed for a struct to defined as containing a pointer to another struct that hasn't yet because all struct pointers are the same size.  Can I not do the same thing with function argument lists?

 

Is there something I can put above the gx_quadpatch_detailer_f typedef to resolve this? 

Edited by carangil

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement