This is kind of a modified version of your question, but depending on what you're doing, something like this might work:
enum {A,B,C};
const int E[] = {0x2E,0x23,0x40};
// Or:
// enum { A = 0x2E, B = 0x23, C = 0x40 };
// const int E[] = {A,B,C};
int isEnum(int x)
{
for(int i=0; i<(sizeof(E)/sizeof(*E)); i++)
{
if(E[i] == x){ return 1; }
}
return 0;
}
int main(void)
{
printf("Value of A: 0x%02x\n", E[A]);
// Or:
// printf("Value of A: 0x%02x\n", A);
printf("isEnum(0x2e): %s\n", isEnum(0x2e) ? "true" : "false");
printf("isEnum(0x2f): %s\n", isEnum(0x2f) ? "true" : "false");
}
which outputs
Value of A: 0x2e
isEnum(0x2e): true
isEnum(0x2f): false
EDIT: TJD beat me to it, and his suggestion of using a sorted array and doing binary search would decrease your search time from n to log(n).