Sujet : Re: C23 enums
De : ldo (at) *nospam* nz.invalid (Lawrence D'Oliveiro)
Groupes : comp.lang.cDate : 20. Jun 2024, 01:50:09
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <v4vuc0$27pi6$1@dont-email.me>
References : 1 2 3 4 5
User-Agent : Pan/0.158 (Avdiivka; )
On Wed, 19 Jun 2024 09:38:24 -0300, Thiago Adams wrote:
On 19/06/2024 04:24, Lawrence D'Oliveiro wrote:
>
On Tue, 18 Jun 2024 08:09:13 -0300, Thiago Adams wrote:
This 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.
... and clarity about the possible values accepted.
As a documentation aid? Again, that’s implementation-specific, nothing to
do with the caller-visible interface.