M
Michael Brennan
I have a menu_item structure containing an union.
func is used if the menu item should use a callback,
and submenu if a popupmen should be shown.
struct menu_item {
enum { function, popup } type;
union {
int (*func)(int);
struct menu_item *submenu;
} action;
};
The problem is that I want to use an initializer to
initialize this structure.
But if I understood what I read in the FAQ right, you can't initialize
the unions in C89, only in C99 with ``designated initializers''.
I could use the C99 feature (I think, I haven't really checked it out),
but I usually try to only code in C89, so I wonder if there is some
good way to solve this in C89 (not absolutely neccessary though).
I could of course just remove the union and only use two regular
variables, func and submenu, and use just one of them depending on
the types.
Or how about using a void pointer, and casting it between a fuction
pointer or a structure pointer?
Any comments are appreciated!
/Michael Brennan
func is used if the menu item should use a callback,
and submenu if a popupmen should be shown.
struct menu_item {
enum { function, popup } type;
union {
int (*func)(int);
struct menu_item *submenu;
} action;
};
The problem is that I want to use an initializer to
initialize this structure.
But if I understood what I read in the FAQ right, you can't initialize
the unions in C89, only in C99 with ``designated initializers''.
I could use the C99 feature (I think, I haven't really checked it out),
but I usually try to only code in C89, so I wonder if there is some
good way to solve this in C89 (not absolutely neccessary though).
I could of course just remove the union and only use two regular
variables, func and submenu, and use just one of them depending on
the types.
Or how about using a void pointer, and casting it between a fuction
pointer or a structure pointer?
Any comments are appreciated!
/Michael Brennan