I think I’ve read somewhere that it is illegal to take the address of an enum value in C (enum values not being lvalues; however, I can’t find any information on this now). Is that correct and, if so, why?
Edit:
Here’s an example that clarifies what I mean by “enum value” above. I mean taking the address of first_value below, not taking the address of an actual instance of an enum:
enum myenum
{
first_value,
second_value
};
“Enum value” is slightly ambiguous; however, I assume you mean the following:
In this case, it is illegal to take the address of
first_value. The reason for this is thatfirst_valuedoes not actually exist in memory anywhere… it is just a constant, effectively another name for the number 0 (of which, of course, you also cannot take the address).If, on the other hand, you mean whether you can take the address of a variable that is declared as an enum:
then that is definitely possible.