Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ensure enum name uniqueness in C without adding long prefix

Tags:

c

enums

c99

I find myself always appending the name of the enum, to its values, because else I often have conflicts with other enums, for example:

typedef enum
{
    A_ONE,
    A_TWO,
} A;

typedef enum
{
    B_ONE,
    B_TWO,
} B;

Is there a nicer way to do this in C?

like image 337
Maestro Avatar asked Nov 13 '22 12:11

Maestro


1 Answers

No, there is not. C++ has namespaces, or enums existing in classes (IIRC), but C is extremely primitive in this regard.

like image 140
djechlin Avatar answered Dec 05 '22 01:12

djechlin