Preprocessor macro to quote its argument
Adrian McCarthy
adrian at mti.mti.com
Mon Aug 20 05:39:46 AEST 1990
In article <1112 at mti.mti.com> adrian at mti.UUCP I wrote:
>Ever needed a preprocessor macro that could quote its argument? [...]
> #define Q "
> #define Q1(x) Q x "
It has been pointed out by several kind folks that this is *not*
ANSI-compliant. ANSI preprocessors do the tokenization of the input for
the rest of the compiler (thus ``preprocessor'' is arguably a misnomer),
so the #define lines would generate errors since the unpaired double-quote
is an incomplete token.
For ANSI preprocessors, use:
#define Q1(x) #x
For pre-ANSI preprocessors, the original solution *may* work. Reportedly,
#define Q1(x) " x "
may even work with many pre-ANSI preprocessors, though not VAX C.
OK, so I was wrong,
Aid. (adrian at gonzo.mti.com)
More information about the Comp.lang.c
mailing list