Every story and comment from the Hacker News API, in a layout borrowed from 2001.
A comment on Type-safe generic data structures in C. Parent comment
In a nutshell:
#define COLOR_LIST \ X( RED ) \ X( GREEN ) \ X( BLUE ) \ X( PURPLE ) enum Color { #define X(code) code, COLOR_LIST #undef X }; static const char* colorNames[] = { #define X(code) #code, COLOR_LIST #undef X };
// --- color.def X( RED, "Red", 0xFF0000 ) X( GREEN, "Green", 0x00FF00 ) X( BLUE, "Blue", 0x0000FF ) // --- color.h enum Color { #define X(code,name,mask) code, # include "color.def" #endif }; static const char* colorNames[] = { #define X(code,name,mask) name, # include "color.def" #undef X }; static unsigned int colorMasks[] = { #define X(code,name,mask) mask, # include "color.def" #undef X };
#undef X
In a nutshell:
You can even make it cleaner and store more metadata: