Electronic – XC8 Compiler array of struct initialization problem

mplabmplabxpicxc8

I'm using MPLAB X IDE with XC8 compiler and I would like to create a menu system to a GLCD module, but I'm having trouble initializing my MainMenuItemsList[] array. I'm not getting error on compliling but if I'm debugging the project, I can see that only the first item is initialized. What can be the cause?

Here is the relevant code fragment:

typedef struct menuitem
{
  char ItemName[10];
  void (*handler)(void);
  struct menu *ChildSubMenu;
}MenuItem;

typedef struct menu
{
  char MenuName[10];
  char NumberItems;
  //struct menu *ParentMenu;
  MenuItem *Items[12];
}Menu;

MenuItem MainMenuItemsList[12] = {  {"SubMenu1", NULL, NULL},
                                    {"SubMenu2", NULL, NULL},
                                    {"SubMenu3", NULL, NULL},
                                    {"SubMenu4", NULL, NULL},
                                    {"SubMenu5", NULL, NULL},
                                    {"SubMenu6", NULL, NULL},
                                    {"SubMenu7", NULL, NULL},
                                    {"SubMenu8", NULL, NULL},
                                    {"SubMenu9", NULL, NULL},
                                    {"SubMenu10", NULL, NULL},
                                    {"SubMenu11", NULL, NULL},
                                    {"SubMenu11", NULL, NULL}
                                };

Menu MainMenu = {"MainMenu",12,&MainMenuItemsList};

Best Answer

when you define MenuItem *Items[12]; you are creating an array of addresses, not an address to an array of structs (which is what you want).

take the "[12]" out:

typedef struct menu
{
  char MenuName[10];
  char NumberItems;
  MenuItem * Items;
}Menu;