Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


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


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 carangil   Members   -  Reputation: 490

Like
0Likes
Like

Posted 06 March 2014 - 09:59 PM

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, 06 March 2014 - 10:01 PM.


Sponsor:

#2 tobiasjs   Members   -  Reputation: 148

Like
6Likes
Like

Posted 06 March 2014 - 10:18 PM

Just add

struct gx_quadpatch_s;

above the function typedef to forward declare the struct.



#3 carangil   Members   -  Reputation: 490

Like
0Likes
Like

Posted 06 March 2014 - 10:34 PM

Wow thanks.  I didn't know I could forward reference a struct like that.  upvote for you!






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS