An alternative:
Code:
#include <stdio.h>
#include <string.h>
#define MACRO(str) (strcmp((str), "WHITE") ? (str) : "BLACK")
int main(void)
{
printf( MACRO("WHITE") );
printf("\n");
return 0;
}
This kind of string substitution is used by e.g. the gettext() package, for internationalization. There, the macro is just
_ , i.e.
printf(_("WHITE"));
Note that the compiler does do some serious logic checking, so the above is not nearly as inefficient as one might think. At least gcc-4.6.1 on x86-64, even with -O0, compiles the above C to exactly the same code as
Code:
#include <stdio.h>
int main(void)
{
printf("BLACK");
putchar('\n');
return 0;
}