5

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?

djechlin
  • 59,258
  • 35
  • 162
  • 290
Maestro
  • 9,046
  • 15
  • 83
  • 116

2 Answers2

2

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

djechlin
  • 59,258
  • 35
  • 162
  • 290
-1

It is your own decision, but you can use the #define directive

#define WHAT_EVER TO_BE_REPLACED

Defines will be replaced from the WHAT_EVER in your code with TO_BE_REPLACED.

After your preprocessor run throw your code, all will be replaced.

zeyorama
  • 444
  • 3
  • 12