Use of Unions can be quite elaborate, but what is clear is
that once you have stored an item into a union structure it
is impossible to retrieve unless you know what type of
variable was stored (in this case an integer or a float). It
follows therefore that you must also store in the node some
kind of a TAG that interprets uniquely the item in the
"variant" field.
Typically we might do this though the use of some defined
constants:
#define INTEGER -1
#define FLOAT 1
struct node {// note datanode creation here
int TAG;
union {
int digits;
float number;
} data;
Nodeptr next;// struct node* next;
} datanode;
|