Just use STRINGIFY x
instead of STRINGIFY(x)
#include <stdio.h>
#define MYVAR 1
#define STRINGIFY(x) #x
#define TO_STRING(x) STRINGIFY x
int main(void)
{
const char *mystring = TO_STRING(MYVAR);
printf("%s\n", mystring);
return 0;
}
TO_STRING(x)
expands to STRINGIFY (1)
when MYVAR
is defined as (1)
If MYVAR
is defined as 1
without parentheses you get a compile time error.