AnsweredAssumed Answered

CW4.5 S12X Initializing unions

Question asked by David Poinsett on Sep 26, 2007
Latest reply on Oct 22, 2007 by Daniel Lundin

Is there a way in CW to control type when initializing union members?

In the code below, all the param elements are initialized as integers even though some are ints and some are floats. If I change the declaration so float appears first in the union, all params are initialized as floats.

I've tried typecasting the assigned values but that doesn't work. Any ideas?

typedef struct {  char *Desc;    union {    int i;    float f;  } Val;} TestStruct;const struct {  char *Desc;  TestStruct Param[2];} List[] = {    {"ListItem1",       "param1", 1,       "param2", 2.0},       {"ListItem2",      "param1", 3.0,      "param2", 4}  };void main(void) {  for(;;) {}}