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

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

Re: [avr-gcc-list] Typdef chick 'n egg situation.. way out ?


From: Dean Ferreyra
Subject: Re: [avr-gcc-list] Typdef chick 'n egg situation.. way out ?
Date: Wed, 21 Jan 2009 09:33:43 -0800
User-agent: Thunderbird 2.0.0.19 (Windows/20081209)

larry barello wrote:
> Use a struct tag, rather than the typdef tag for your storage type, as:
> 
> typedef struct _TMenu
> {
>       ...
>       struct _TMenuItem items[];
> }
> TMenu;
> 
> typedef struct _TMenuItem
> {
>       ...
>       struct _TMenu *ptr;
>       ...
> }
> MenuItem;

BTW, avr-gcc complains for me about the items field: "array type has
incomplete element type".  Reversing the order of the definitions
worked for me, like so:

typedef struct _TMenuItem
{
        ...
        struct _TMenu *ptr;
        ...
}
MenuItem;

typedef struct _TMenu
{
        ...
        struct _TMenuItem items[];
}
TMenu;

Also, Vince, do you really mean to use a "flexible array" for the
items field; i.e., leaving the size of items unspecified?

Dean

> -----Original Message-----
> Subject: [avr-gcc-list] Typdef chick 'n egg situation.. way out ?
> 
> Hi list,
> 
> 
> Problem: I have two typdef's statement, each type contains a pointer to
> the other type ! Hmmm....
> 
> 
> typedef TMenuItem struct {
>       char    text[20];
>       TMenu   *ptr;
>       void (*fptr)();
> };
> 
> typedef TMenu struct {
>       uint8_t         nb;
>       char            title[20];
>       TMenuItem       items[];
> };
> 
> 
> I am basically rewriting (following a computer crash..) a program I did
> 3+ years ago.. all from memory. Back then ISTR some kind soul on here,
> sorted me out with something he called "forward declaration"... but I
> can't seem to manage to find this particular post in the list archive
> sadly.
> 
> I think it was a line just saying "TMenu" will be defined further down,
> don't worry Mister GCC and just accept my TMenuItem struct below, you
> will find TMenu soon enough. Something to that effect ! ;-)
> 
> 
> TIA...
> 
> Regards,
> 
> --
> Vince





reply via email to

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