C
This is not possible in C because all enumeration constants from the different enumerations that are in scope are part of the same namespace called the ordinary identifiers namespace. So using the same name for the constants will result in a re-declaration error.
As per C11 standard:
6.2.3 Name spaces of identifiers
- Thus, there are separate name spaces for various categories of identifiers, as follows:
...
— all other identifiers, called ordinary identifiers (declared in ordinary declarators or as enumeration constants).
C++
This is possible in C++, if you use scoped enumerations.
enum class all_personnel {
// male
TONY,
MIKE,
JIM,
// female
JESSICA,
MARY,
} ;
enum class male_personnel {
TONY,
MIKE,
JIM,
} ;
However, note that there are no implicit conversions from the values of a scoped enumerator to integral types or from one scoped enumerator to another scoped enumerator.
This is because each enumerator becomes a named constant of the enumeration's type.
So the below is not possible:
male_personnel mp2 = all_personnel::TONY; //will not work
all_personnel ap2 = male_personnel::MIKE; //will not work
and neither is this:
male_personnel mp1 = male_personnel::MIKE;
all_personnel ap1 = all_personnel::TONY;
mp1 = ap1; //will not work
See Demo