I'm curious about usage syntax enumin struct(in C)
I saw various examples in which the struct+ union/ combination was used to create a complex type enum, for example:
struct MyStruct{
enum{
TYPE_1,
TYPE_2,
TYPE_3,
} type;
union{
int value_1;
int value_2;
int value_3;
} value;
};
struct MyStruct test_struct;
In any case, from this example, how can I store / test the current "type" according to the field enum?
If I have a pointer to test_struct, this does not work; discarding an unknown element error:
struct MyStruct *test_pointer = &test_struct;
test_pointer->value = test_pointer->VALUE_1;
I'm just wondering, do I need to access values enumas global values?
test_pointer->value = VALUE_1;
Any clarification would be greatly appreciated.
source
share