• Re: C23 enums

    From Lawrence D'Oliveiro@21:1/5 to Thiago Adams on Tue Jun 18 07:00:27 2024
    On Sat, 15 Jun 2024 06:04:58 -0300, Thiago Adams wrote:

    I realized we can have "private" enums in C23, because they are
    completed types. Values of E does not need to be at header file.

    enum E : int;

    struct X{
    enum E e;
    };

    What would be the point of this?

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Lawrence D'Oliveiro@21:1/5 to Thiago Adams on Wed Jun 19 07:24:09 2024
    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?

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Lawrence D'Oliveiro@21:1/5 to Thiago Adams on Thu Jun 20 00:50:09 2024
    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.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)