GCC preprocessor macro: inserting x and x does not give a valid preprocessing token

#define PATH "yagh/headers/" #define FILNAME "includefile" #define CONCAT(a__, b__) CONCAT_DO(a__, b__) #define CONCAT_DO(a__, b__) a__##b__ #define CONCATTHREE(a__, b__, c__) CONCAT(CONCAT(a__, b__), c__) #define STRINGIFY(a__) #a__ #include STRINGIFY(CONCATTHREE(PATH ,FILNAME ,.h)); 

This macro works fine in the VS compiler, but does not compile in the GCC compiler:

Error: error: inserting "/" and "includefile" does not give a valid preprocessing token

and for some included files it gives an error:

Error: insert "includefile" and "." does not give a valid pre-processing token

+6
c gcc c-preprocessor string-concatenation stringification
source share
1 answer

GCC is a little stricter in enforcing the C standard: see Macro ## Concatenation Operator Differences Between Visual-C ++ and gcc and http://gcc.gnu.org/onlinedocs/gcc-4.3.3/cpp/Concatenation.html #Concatenation .

You can try #include STRINGIFY(PATH FILNAME.h) (lack of space between FILNAME and .h important) - this works for me with gcc 4.6.3.

+1
source share

All Articles