D
DJTB
Dear Group,
I'd like to check if a value is defined in an enum.
Example:
------------------------------------------------------
typedef enum
{
A_VALUE = 1,
SOME_OTHER_VALUE = 8,
ANOTHER_VALUE = 21,
/* a few hundred more values... */
YET_ANOTHER_VALUE = 45770
} VALUES;
VALUES test;
test = 1; /* OK, because 1 is defined in VALUES (as SOME_VALUE) */
test = 2; /* NOT OK, because 2 is not defined in VALUES */
------------------------------------------------------
My compiler checks if an assigned value is defined in an enum at
compile-time, but I'd like to check it at run-time.
It might be possible using a switch, and check each (maybe a hundred) value
in the enum, but this is difficult to maintain, especially if the enum
changes, I'd have to update each validate switch.
I'd like to know if there's a clever Macro or programming method which
validates a value in an enum?
Thanks in advance,
Stanley
I'd like to check if a value is defined in an enum.
Example:
------------------------------------------------------
typedef enum
{
A_VALUE = 1,
SOME_OTHER_VALUE = 8,
ANOTHER_VALUE = 21,
/* a few hundred more values... */
YET_ANOTHER_VALUE = 45770
} VALUES;
VALUES test;
test = 1; /* OK, because 1 is defined in VALUES (as SOME_VALUE) */
test = 2; /* NOT OK, because 2 is not defined in VALUES */
------------------------------------------------------
My compiler checks if an assigned value is defined in an enum at
compile-time, but I'd like to check it at run-time.
It might be possible using a switch, and check each (maybe a hundred) value
in the enum, but this is difficult to maintain, especially if the enum
changes, I'd have to update each validate switch.
I'd like to know if there's a clever Macro or programming method which
validates a value in an enum?
Thanks in advance,
Stanley