cl search engine

måndag, april 28, 2008

c preprocessor tricks C #define enum macro macros string concatenation

c preprocessor tricks C #define enum macro macros string concatenation:

"#include

#define NAMES C(RED)C(GREEN)C(BLUE)

#define C(x) x,

enum color { NAMES TOP };

#undef C

#define C(x) #x,

const char * const color_name[] = { NAMES };

int main( void )
{ printf( 'The color is %s.\n', color_name[ RED ]);
printf( 'There are %d colors.\n', TOP ); }"

tisdag, april 01, 2008