[LCP] Circular Struct Definitions
Moises Silva
moises.silva at gmail.com
Fri Mar 6 02:20:16 EST 2009
http://en.wikipedia.org/wiki/Forward_declaration
2009/3/2 Christopher Howard <choward at indicium.us>:
> I'm writing these structs to represent two ideas in my program: one is menu
> items and the other is menus (i.e., lists of menu items -- I call them
> "Bundles"). The problem is that I not only want menus to contain arrays of
> menu items, but I also want menu items to contain references to other menus.
> The purpose of this is to allow for "sub-menus", so that selecting a menu
> item takes the user to another menu.
>
> /* MY CODE START */
>
> typedef struct {
> char command[256];
> char key_assignment;
> char label[256];
> MenuItem_Bundle * sub_menu;
> } MenuItem;
>
> typedef struct {
> MenuItem * menuitem_array;
> MenuItem_Bundle * owning_menu;
> } MenuItem_Bundle;
>
> /* MY CODE END */
>
> Here is the errors from the gcc compiler:
>
> In file included from /scratch/choward/wrk/minmenu/src/process_cfg.h:5,
> from /scratch/choward/wrk/minmenu/src/minmenu.c:23:
> /scratch/choward/wrk/minmenu/src/menuitem.h:8: error: expected
> specifier-qualifier-list before ‘MenuItem_Bundle’
> /scratch/choward/wrk/minmenu/src/menuitem.h:13: error: expected
> specifier-qualifier-list before ‘MenuItem_Bundle’
> make[2]: *** [src/CMakeFiles/minmenu.dir/minmenu.o] Error 1
> make[1]: *** [src/CMakeFiles/minmenu.dir/all] Error 2
> make: *** [all] Error 2
>
> I imagine the problem is due to the circular nature of the definitions.
> Is there a way that I could make this work the way I want?
>
> Thank you in advance.
>
> --
> Christopher Howard
> http://indicium.us
> http://theologia.indicium.us
> _______________________________________________
> This is the Linux C Programming List
> : http://lists.linux.org.au/listinfo/linuxcprogramming List
>
>
--
"I do not agree with what you have to say, but I’ll defend to the
death your right to say it." Voltaire
More information about the linuxCprogramming
mailing list