typedef enum {
TYPE_A = 0,
TYPE_B,
TYPE_C
} OBJTYPE;
Assume there is the enum type above.
I’m using arm-g++ for my working.
And some macro for any type is defined like this:
#define ANY_TYPE ((OBJTYPE)-1)
But following comparision was false as I tested:
if (param->type == ANY_TYPE) something();
else error();
param->type was set as ANY_TYPE and its type was OBJTYPE. I logged both of them with ‘%d’ and they were displayed as 255. But it’s false and error occurred.
This problem has been not caused from RVCT (commercial arm compiler).
Why does it fail?
-1 is an illegal value for your enumeration.
The language standard (7.2 Enumeration declarations) says:
According to this, legal values are 0, 1, 2 and 3 (those values that can be represented with two bits). You should add the
ANY_TYPEenumerator to use it.