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: Vincent Trouilliez
Subject: Re: [avr-gcc-list] calling function pointers via pointers ?
Date: Thu, 29 Sep 2005 15:12:46 +0200

On Thu, 2005-09-29 at 14:24 +0200, David Brown wrote:
> You've picked a chalenge with your complex menu structures, but you are
> definitely going about it the right way.  Unconstrained arrays are almost
> certainly the most elegant way to deal with the structures - when you figure
> them out fully, you'll be glad you stuck by it.  Just take it slowly,
> building your structure piece by small, understandable piece, with
> carefully-named typedefs.

Okay David, I just reworked my code a bit inspired by your comments and
declarations example. I am not sure I quite follow the ins and outs of
the syntax of typedefs, but the following works fine:


typedef struct {
        char    name[21];       
        void    (*fp) (uint8_t);
}menu_item;


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

>From my perspective, it's perfect:

1) menus are defined completely in one single data type/struc, instead
of having part of the data pulled out (like was suggested earlier).

2) it's scaleable/unconstrained, and doesn't waste a single byte of ROM.

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...


--
Vince





reply via email to

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