You can define it, sort of, but it involves some boiler-plate that isn't all too pleasant, and pollutes the global/tag namespace a lot/bit.
If you leverage the notorious X macros for the job, it would look like this:
#define LIST_OF_ENUM_IDS \
X(A, 0) \
X(B, 1) \
X(C, 2) \
X(D, 4) \
X(E, 6) \
X(F, 8) \
X(G, 10)
#define X(id, val) \
id = val,
typedef enum
{
LIST_OF_ENUM_IDS
} my_enum;
#undef X
#define X(id, val) id##_impl_helper,
enum my_enum_impl_helper__ {
LIST_OF_ENUM_IDS
MY_ENUM_MAX_ELEMENTS
};
#undef X
Live example: On Ideone
Alternatively, some shops will instead rely on bold comments and code reviews to catch such things:
/********************************************
*
**
*** ATTENTION! Remember to bump MAX_ELEMENTS
*** should you add new values to the enum
**
*
********************************************/
typedef enum
{
A= 0,
B= 1,
C =2,
D= 4,
E= 6,
F= 8,
G= 10,
MAX_ELEMENTS = 7 /// Bump this if you add new values!
}my_enum;
Which can work not all too bad, despite the human factor.