avr-gcc-list
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [avr-gcc-list] calling function pointers via pointers ?


From: Dave Hansen
Subject: Re: [avr-gcc-list] calling function pointers via pointers ?
Date: Thu, 29 Sep 2005 10:01:31 -0400

From: Vincent Trouilliez <address@hidden>
[...]
What more could I possibly want ? Well, there is one thing actually:
the pointer points to a function, any function. However if the item is
actually a sub-menu, then the 'menu_item' structure needs to store a
pointer to a 'menu' structure, so that I know what sub-menu to run.
So it would like this:

typedef struct {
        char    name[21];
        void    (*fp) (uint8_t);
        menu *sub_menu;   // I need to know what sub-menu to run !
}menu_item;


typedef struct menu {
        char title[21];
        uint8_t nb;
        menu_item items[];
}menu;

But it's a bit strange no ? :-/ How can I declare a pointer of 'menu'
type... even before said type has been declared ! The two structures
would be interdependent... no solution in sight ! :o((((

I guess this is crap code again... heeelp...

Not strange.  No crap.  You're just missing a feature.

C allows you to forward-declare a structure with a tag. What you need is something like

  struct menu;    // Forward declaration

  typedef struct {
     char       name[21];
     void       (*fp) (uint8_t);
     struct menu *sub_menu;  // can't use typedef here
  }menu_item;

  typedef struct menu {
     char title[21];
     uint8_t    nb;
     menu_item items[];
  }menu;

Warning: untested code, but it should be close.  HTH,
  -=Dave






reply via email to

[Prev in Thread] Current Thread [Next in Thread]