P99
|
◆ P99_DECLARE_ENUM
Value:
\
enum T { __VA_ARGS__ , \ \
P99_PASTE2(T, _amount), \ \
P99_PASTE2(T, _max) = ((size_t)(P99_PASTE2(T, _amount)) - 1u), \ \
P99_PASTE2(T, _min) = 0 \
}; \ \ \
typedef enum T T; \
P99_DECLARE_ENUM_GETNAME(T, __VA_ARGS__); \
P99_DECLARE_ENUM_PARSE(T, __VA_ARGS__)
Declare a simple enumeration type. This macro only works for enumeration types that have no assignments to the constants. To define an enumeration type P99_DECLARE_ENUM(color, red, green, blue);
As additional benefits you obtain:
To have this work, you have to put a line P99_DEFINE_ENUM(color);
in one of your object files. Unfortunately you can't use doxygen like comments inside the argument list to document the enumeration constants. You have to document the constants separately. For the example above you would do /// the most reddish color of all colors
Observe the bizarre naming convention, here. Although in C (and C++) ‘red’ is declared in the same scope as ‘enum color’ you have to prefix it with ‘color’ such that the documentation ends up inside the one for ‘color’.
Definition at line 139 of file p99_enum.h. |