Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Preprocessor macro GCC: pasting 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 VS compiler but does not compile on GCC compiler:

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

and for some include files it gives the error:

Error: pasting "includefile" and "." does not give a valid preprocessing token

like image 314
SoccerKid Avatar asked Jan 12 '11 10:01

SoccerKid


1 Answers

GCC is being a bit stricter in enforcing the C standard: see Differences in Macro ## concatenation operator between Visual-C++ and gcc and http://gcc.gnu.org/onlinedocs/gcc-4.3.3/cpp/Concatenation.html#Concatenation.

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

like image 161
bks Avatar answered Oct 01 '22 02:10

bks