Friday, August 7, 2009

A portable way to pass a string to C as a macro


#define STRINGIZE_(x) #x
#define STRINGIZE(x) STRINGIZE_(x)


And call STRINGIZE(x) in subsequent code. This is useful when using the -D option in gcc -- without STRINGIZE(), extra double-quotes (\") must be added in order to pass strings as macros from the command line.

No comments: