M
Marius Lazer
So you're using the C preprocessor to produce code in a language other
than C?
Have you considered using some other preprocessor? (m4, maybe?)
If the fact that it happens to work on one specific implementation is
good enough for you, that's fine. You should just be aware that it
invokes undefined behavior, and it could easily fail in arbitrarily
bad and subtle ways under other implementations.
I'm not playing tricks. I'm using embedded SQL in C/C++ code (Pro*C/C++
for Oracle and Esql-C/CC for Ingres) and no, I don't like "hacky"
solutions. Fortunatelly, the trick proposed by Robert and the one below
won't compile if the *feature* is not supported by the compiler's
preprocessor.
I did some reading on Boost preprocesoor metaprogramming and here's
another solution (perhaps I rushed bugging you folks):
#include <boost/preprocessor/cat.hpp>
#define QUOTE(x) '
#define START_QUOTE(x) BOOST_PP_CAT(QUOTE(x), x)
#define QUOTE_ARG(x) BOOST_PP_CAT(START_QUOTE(x), QUOTE(x))
QUOTE_ARG(foo) // expands to 'foo' on gcc 4.0.2
I would have liked this to work but I get a cpp error even though it
still expands to 'foo':
#define QUOTE(x) '
#define QUOTE_ARG(x) BOOST_PP_CAT(QUOTE(x), BOOST_PP_CAT(x, QUOTE(x)))
Marius