TL;DR: Is it right to assume, given enum NAME {...};
, that enum NAME n
is the same as int n
during execution? Can n
be operated on as if it were a signed int
, even though it is declared as enum NAME
? The reason: I really want to use enum
types for return flags, as a type 'closed' with respect to bit-operations.
For example: Let typedef enum FLAGS { F1 = 0x00000001, F2 = 0x00000002, F3 = 0x00000004 } FLAGS ;
Then, FLAGS f = F1 | F2;
assigns 3
to f
, throwing no related errors or warnings. This and numerous other compiler-permitted usage scenarios, such as f++
, makes me think I could legit treat f
as if it were a signed int
. Compiler used: MSVC'19, 16.9.1, with setting "C17 (2018) Standard (/std:c17)";
I searched the standard (the sketch here) and looked at other related questions, to find no mention of what suspect (and wished) to be a "silent promotion" of enum NAME x
to signed int x
, even though the identifiers have that type. This leads me to believe that the way enum
behaves when assigned a value that isn't a member, is implementation dependent. I'm asking, in part, in order to confirm or deny this claim.