C preprocessor stringification weirdness
问题 I am defining a macro that evaluates to a constant string, holding the filename and the line number, for logging purposes. It works fine, but I just can't figure out why 2 additional macros are needed - STRINGIFY and TOSTRING , when intuition suggests simply __FILE__ ":" #__LINE__ . #include <stdio.h> #define STRINGIFY(x) #x #define TOSTRING(x) STRINGIFY(x) #define THIS_ORIGIN (__FILE__ ":" TOSTRING(__LINE__)) int main (void) { /* correctly prints "test.c:9" */ printf("%s", THIS_ORIGIN);