Practice ยท 1 of 2
Build the X-Macro Table
The boilerplate defines a color table via X-macros:
``c
#define COLORS \
X(RED, 0xFF0000) \
X(GREEN, 0x00FF00) \
X(BLUE, 0x0000FF)
`
Implement the two views over it (the enum and lookup are YOURS to write
using COLORS):
`c
/* the enum must contain CLR_RED, CLR_GREEN, CLR_BLUE (via pasting),
plus CLR_COUNT as the sentinel */
/* returns the enum value for name ("RED" -> CLR_RED), or -1 */
int clr_from_name(const char *name);
/* returns the hex value for the enum, or -1 */
long clr_hex(int clr);
``
Difficulty: intermediate
Press Submit to check your solution.
Back to lesson: Practice: X-Macro & Assert Gym