Post by Thiago AdamsPost by Lawrence D'OliveiroPost by Thiago AdamsThis creates a kind of encapsulation.
Why not just use “int” or “unsigned int”? Why does the caller even need to
know it’s an enum?
The advantage will be the type check at the implementation file (some
compiler have extra type check for enuns) ...
Obviously this is not a language requirement, so I’m not sure of the
point. E.g. GCC compiles this rather flagrant example without complaint:
enum colours {red, green, blue};
enum colours colour = 9;
I even tried “-Wall -Wpedantic”, to no effect.
Post by Thiago Adams... and clarity about the possible values accepted.
As a documentation aid? Again, that’s implementation-specific, nothing to
do with the caller-visible interface.