Hello every one.
I'm developing a menu system for a embedded device. i designed a struct and some core functions. i need all menu items in ordered some way. but when i try to compile this code faced with error { initializer element is not a constant }. here is sample code with comments. how can i solve this problem.
(complier gcc)
Code:
#include <stdio.h>
typedef struct _MENUITEM { // this struct have details of menu items
unsigned char* title; // title bar
struct _MENUITEM * topItem; // if this item have parent, pointer of this parent, if dont have 0
struct _MENUITEM * subItems; // if this item have sub items, pointer of first item, if dont have subitems 0
} _menuItem;
#define ITEM_1_IND 0 // order of menu items
#define ITEM_2_IND 1
#define ITEM_3_IND 2
#define ITEM_4_IND 4
#define ITEM_5_IND 5
#define ITEM_6_IND 6
#define ITEM_7_IND 8
const _menuItem itemOne; // definitions
const _menuItem itemTwo;
const _menuItem itemThree;
const _menuItem itemFour;
const _menuItem itemFive;
const _menuItem itemSix;
const _menuItem itemSeven;
_menuItem * const itemsArray[] = { // now i can reach items ordered
&itemOne,
&itemTwo,
&itemThree,
0,
&itemFour,
&itemFive,
&itemSix,
0,
&itemSeven,
0};
// error in this line. {initializer element is not a constant}
const _menuItem itemOne = {"one", 0, itemsArray[ITEM_2_IND]};
// one have no parent item and it have subitem(s). this items start from second(ITEM_2_IND=1) item of itemsArray
const _menuItem itemTwo = {"two", itemsArray[ITEM_1_IND], itemsArray[ITEM_4_IND]};
const _menuItem itemThree = {"three", itemsArray[ITEM_1_IND], itemsArray[ITEM_7_IND]};
int main(void) {
printf ("hello");
return EXIT_SUCCESS;
}