Make sure the uniqueness of an enumeration name in C does not contain a long prefix

I always add the name of an enumeration to its values, because otherwise I often have conflicts with other enumerations, for example:

typedef enum
{
    A_ONE,
    A_TWO,
} A;

typedef enum
{
    B_ONE,
    B_TWO,
} B;

Is there a better way to do this in C?

+5
source share
2 answers

No no. C ++ has namespaces or enumerations that exist in classes (IIRC), but C is extremely primitive in this regard.

+2
source

This is your own solution, but you can use the #define directive

#define WHAT_EVER TO_BE_REPLACED

Definitions will be replaced with WHAT_EVERin your code with TO_BE_REPLACED.

After your preprocessor runs your code, everything will be replaced.

-1
source

All Articles