ANSI CPP string concatenation

Pyung-Chul Kim pckim at unisql.UUCP
Fri Jun 21 00:46:52 AEST 1991


In article <1271 at cnw01.storesys.coles.oz.au> nigel at cnw01.storesys.coles.oz.au (Nigel Harwood) writes:
>Does anyone know if you can append strings in ANSI C.
>
>For example I want a macro which appends one of its numeric
>arguments to a string coded into the marco.
>
>#define	APPEND(x,v)	{ donothing+x = v; }
>
>I know that the '+' isn't what I'm after but using whatever the method
>turns out to be what I want it to generate from APPEND(1,123) is:
>
>	{ donothing1 = 123; }
>

FAQ 37. says that we can use ## for this purpose.
	37.  I have some old code that tries to construct identifiers with a
	     macro like "#define Paste(a, b) a/**/b", but it doesn't work any
	     more.

	     A:   Try the ANSI token-pasting operator ##.
That is,

#define	APPEND(x,v)	{ donothing ## x = v; }

Hope it helps


-- 
Pyung-Chul Kim

UniSQL, Inc.
9390 Research Blvd., Kaleido II, Suite 220, Austin, TX 78759
Internet: execu!sequoia!unisql!pckim at cs.utexas.edu
UUCP: {uunet, cs.utexas.edu!execu}!sequoia!unisql!pckim
TEL: (512)343-7297 Ext. 332
FAX: (512)343-7383



More information about the Comp.lang.c mailing list