Quoting the contents of a #define
I want to print the contents of a VC Preprocessor Definition (essentially a #define set by the IDE - such as X=ABC).
When I do the following:
printf("%s", X);
I get the compiler error:
error C2065: 'ABC': undeclared identifier
This makes sense to me... but the net effect that I want to acheive is
printf("%s", "X"); /* Where the preprocessor define X resolves to value ABC */
You might think why am I being so dense - by not simply hard code "ABC" since I'm setting this value statically within the VC IDE... The effect would be the same...
Well - I need to compile this code on mulitple O/S'es and want the value of X to be set by my build script...
Answer found... sorry to have trouble you...
QUESTION
How do I convert a constant passed to a #define macro into a text string?
ANSWER
Pass the parameter to a stringizing macro as shown below:
#define NUMBER B85800 // this can be defined in the command line
#define VAL(str) #str
#define TOSTRING(str) VAL(str)
unsigned char part1[10] = TOSTRING (NUMBER); // generates "B85800"
unsigned char part2[10] = VAL(NUMBER); // generates "NUMBER"