Question with cpp and token pasting

Doug Gwyn gwyn at smoke.brl.mil
Fri Feb 1 05:47:07 AEST 1991


In article <1991Jan30.232740.1697267 at locus.com> bringo at locus.com (Bob Ringo) writes:
>Hi, this is probably a simple task, but I haven't figured it out.
>I'd like to do the following:
>#define A "Good"
>#define B "Morning"
>#define C   /* the concatenation of A and B */

This is an ill-defined requirement..

>--I tried the following, but it didn't work.
>#define paste(x,y)  x ## y
>#define A "Good"
>#deifne B "Morning"
>#define C paste(A,B)

I suppose for your purposes the following would suffice:
#define A "Good"
#define B "Morning"
#define C (A B)
Note that string-literal splicing is a new feature with ANSI C and
that it occurs AFTER the preprocessing phases.



More information about the Comp.lang.c mailing list