How to initialize unions
Roy Smith
roy at phri.UUCP
Wed Apr 5 07:03:51 AEST 1989
I've got a structure which looks like:
struct ident {
char *name;
int type;
union {
double f;
int i;
} value;
};
and I want to initialize the name, type, and value.i elements of an array
of them them at compile time. Trying the obvious:
struct ident idlist[] = {
{"foo", KEYWORD, KW_FOO},
{"bar", KEYWORD, KW_BAR},
{"baz", KEYWORD, KW_BAZ}
};
draws an error from the compiler, "operands of = have incompatible types"
for each of the 3 lines. Is there any way to do what I want to do?
--
Roy Smith, System Administrator
Public Health Research Institute
{allegra,philabs,cmcl2,rutgers,hombre}!phri!roy -or- roy at phri.nyu.edu
"The connector is the network"
More information about the Comp.lang.c
mailing list