Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[C] Definicja typów zależnych w jednym pliku nagłówkowym

2 views
Skip to first unread message

Piotr

unread,
Jan 2, 2010, 8:47:33 AM1/2/10
to
Witam serdecznie,

Czy istnieje możliwość prawidłowej definicji w jednym pliku
nagłówkowym, typów, które są od siebie zależne? Chodzi mi o taki
przykład:

------------%<------------

// menu.h
#ifndef MENU_H_
#define MENU_H_

#include "menu.h"

typedef menu_item_t* menu_t;

typedef struct{
char* text;
menu_t* submenu;
void (*function)();
} menu_item_t;

#endif /* MENU_H_ */

------------%<------------

Jak widać pole submenu typu menu_item_t jest typu menu_t, które to z
kolei jest typem menu_item_t*.

Jak to prawidłowo zadeklarować?

Z góry dziękuję za zaangażowanie.

--
Piotr Piwko
http://www.embedded-engineering.pl/

twardy C

unread,
Jan 2, 2010, 11:15:47 AM1/2/10
to
‟Piotr” silnie zaprogramował/a:

> typedef menu_item_t* menu_t;
>
> typedef struct{
> char* text;
> menu_t* submenu;
> void (*function)();
> } menu_item_t;

> Jak widać pole submenu typu menu_item_t jest typu menu_t, które to z
> kolei jest typem menu_item_t*.
nazwij strukturę.
--
―oh yea, i got it!
―oh, stupid!
D. Icke

--- news://freenews.netfront.net/ - complaints: ne...@netfront.net ---

Krzysztof Rudnik

unread,
Jan 3, 2010, 4:54:30 AM1/3/10
to
Piotr wrote:

nie pisać typedef tylko bezpośrednio struct.
Do zdefiniowania wskaźnika na strukturę nie potrzeba znać bebechy tej
struktury, tylko fakt że to jest struktura.

definicja
struct xxx * ptr;

Przejdzie nawet gdy xxx jest nieznane.

Krzysiek

0 new messages