[LCP] Circular Struct Definitions

Christopher Howard choward at indicium.us
Tue Mar 3 11:45:42 EST 2009


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


More information about the linuxCprogramming mailing list