GCC tells me you can’t use the same names for separate enumerated type values, e.g.
enum flag_one {
SUCCESS,
FAIL
}
enum flag_two {
SUCCESS,
FAIL
}
is not allowed by the compiler. So scoping is not ‘witihin’ the enum definition?
Is the approach to do something like:
enum flag_one {
FLAG_ONE_SUCCESS,
FLAG_ONE_FAIL
}
enum flag_two {
FLAG_TWO_SUCCESS,
FLAG_TWO_FAIL
}
Slightly confused as I like using enums for return integer codes as its more readable/descriptive but I’m already starting to get name clashes
No. This is not allowed. Enumerator lists define constants. Your
enums happen to be in the same scope — the file scope. You cannot have two constants with the same name within the same scope.From the draft of CX:
Also, from footnote 127 (which is technically non-normative and for informational purposes only):
.
Use
EXIT_SUCCESSandEXIT_FAILUREdefined instdlib.h.