B
Bill Reid
OK, let's say that have a function menu structure declaration
like this (since I basically do):
typedef struct function_item {
char *descrip;
void(*function)(void);
} t_function_item;
typedef struct function_menu {
unsigned short num_items;
unsigned short default_item;
char *title_prompt;
t_function_item *function_items;
} t_function_menu;
Now sometimes (really just about all the time) I want to initialize it to
literal values. So this is how I do it (sort of) for a local function that
selects
a function and runs it (code that doesn't illustrate the question elided):
void my_function_1(void) {
}
void my_function_2(void) {
}
unsigned short run_function_menu(t_function_menu *function_menu) {
}
void select_function(void) {
static t_function_menu my_function_menu=
{0,0,"My Function Menu"};
static t_function_item my_function_items[]={
{"My Function 1",my_function_1},
{"My Function 2",my_function_2},
{NULL,NULL}};
my_function_menu.function_items=my_function_items;
run_function_menu(&my_function_menu);
}
My question is: for some reason if I try to initialize the menu
structure in one fell swoop, with what seems to me to be a legal
initialization, like this:
static t_function_menu my_function_menu=
{0,0,"My Function Menu",(t_function_item []){
{"My Function 1",my_function_1},
{"My Function 2",my_function_2},
{NULL,NULL}}};
I just get a bunch of syntax errors, but to me, the above seems
to be functionally identical to what I actually have to do as shown in
the select_function() example to get the thing to work...why am I
getting the errors, and IS there some way to initialize such a structure
in one initialization assignment? What am I missing here?
like this (since I basically do):
typedef struct function_item {
char *descrip;
void(*function)(void);
} t_function_item;
typedef struct function_menu {
unsigned short num_items;
unsigned short default_item;
char *title_prompt;
t_function_item *function_items;
} t_function_menu;
Now sometimes (really just about all the time) I want to initialize it to
literal values. So this is how I do it (sort of) for a local function that
selects
a function and runs it (code that doesn't illustrate the question elided):
void my_function_1(void) {
}
void my_function_2(void) {
}
unsigned short run_function_menu(t_function_menu *function_menu) {
}
void select_function(void) {
static t_function_menu my_function_menu=
{0,0,"My Function Menu"};
static t_function_item my_function_items[]={
{"My Function 1",my_function_1},
{"My Function 2",my_function_2},
{NULL,NULL}};
my_function_menu.function_items=my_function_items;
run_function_menu(&my_function_menu);
}
My question is: for some reason if I try to initialize the menu
structure in one fell swoop, with what seems to me to be a legal
initialization, like this:
static t_function_menu my_function_menu=
{0,0,"My Function Menu",(t_function_item []){
{"My Function 1",my_function_1},
{"My Function 2",my_function_2},
{NULL,NULL}}};
I just get a bunch of syntax errors, but to me, the above seems
to be functionally identical to what I actually have to do as shown in
the select_function() example to get the thing to work...why am I
getting the errors, and IS there some way to initialize such a structure
in one initialization assignment? What am I missing here?