Using dot to reference an enum value
I'm using MPLab X v5.15 and XC16 1.36
I have built some structures for variables and throughout my program, I'm use the dot to reference various elements.
i.e. int32Number = nPage.Cycler.Object.CycleCounter.Value
The details of my example above are not important. It's just a structure with some elements such as named ints and strings.
I realize that the dot is supposed to select an element of a structure. However, I've discovered that if I type the name of an enum and then type dot, the editor shows me a list of the named values and I can select one. However, at compile time, there is an error "
expected expression before 'enum name' ".
I know that an enum doesn't have elements per se, so how could the dot select anything. An enum is a named list of integers. Without a typedef, it behaves more like a list of defines except that the values are limited to int. However, the MPLab X editor does allow you to type such a syntax as if it understands what you are trying to do, so it has left me wondering why the compiler chokes on it.
Just wondering if there's a way to use the dot syntax with an enum and have it work.
i.e.
typedef enum __attribute__ ((packed)) _COLORS {
BLACK = 0,
BLUE = 31,
BROWN = 48192,
GREEN = 2016,
YELLOW = 65504,
RED = 63488,
GRAY = 33840,
WHITE = 65535
} COLORS;
COLORS myColor;
// this fails to compile...
myColor = COLORS.WHITE;
// but this works fine...
myColor = WHITE;