0

trying to stringize preprocessor variable that contains "-linux-" seems to replace that sub-string without any warning:

bd.cpp

#include <boost/preprocessor/stringize.hpp>

#ifdef XVAR
#pragma message "XVAR = " BOOST_PP_STRINGIZE(XVAR)
#endif

int main() {
  return 0;
}

g++ ./bd.cpp -DXVAR=/usr/lib/x86-test-obj

results in:

In file included from ./bd.cpp:1:0:
./bd.cpp:4:50: note: #pragma message: XVAR = /usr/lib/x86-test-obj
 #pragma message "XVAR = " BOOST_PP_STRINGIZE(XVAR)

while

g++ ./bd.cpp -DXVAR=/usr/lib/x86-linux-obj

results in:

In file included from ./bd.cpp:1:0:
./bd.cpp:4:50: note: #pragma message: XVAR = /usr/lib/x86-1-obj
 #pragma message "XVAR = " BOOST_PP_STRINGIZE(XVAR)

(note the replacement of "-linux-" by "-1-"). Is there a way how to prevent this from happening ? And for curiosity - does anyone know why is that happening ?

Thanks, Pavel

  • Your curiosity will be satisfied [here](http://stackoverflow.com/questions/19210935/why-does-the-c-preprocessor-interpret-the-word-linux-as-the-constant-1?lq=1). Doesn't it work without `BOOST_PP_STRINGIZE` ? Edit : after re-reading, no it won't. Hm. – Quentin May 06 '15 at 12:02
  • Thanks. The original code where the problem appeared was actually assigning the `XVAR` variable into a `std::string`, which was why the strinigzing is needed. Anyway, based on the [link](http://stackoverflow.com/questions/19210935/why-does-the-c-preprocessor-interpret-the-word-linux-as-the-constant-1?lq=1) you posted, I simply undefined the`linux` preprocessor variable. (in the example posted here it was enough to add `-Ulinux` to the gcc command, in the real code I had to do it via `#undef` directly in the source code) – user299033 May 07 '15 at 12:55
  • Yeah, that works. Would be cool to know a workaround for arbitrary macro names collisions though. – Quentin May 07 '15 at 13:02

0 Answers0