[comp.lang.c] Concatenating tokens that aren't parameters to macros in ANSI C

cssrccb@cc.brunel.ac.uk (Cornelia Boldyreff) (08/16/88)

Regarding item on this subject from: gnu@hoptoad.uucp (John Gilmore)
Under pcc:
>#define LFD 6
>#define LHIGH 1.0e+LFD

which expanded LHIGH to

>1.0e+6
and the problems he's had getting this to work in ANSI C with gcc.
There is a simple solution given below:

#define paste(a,b) a ## b
#define xpaste(a,b) paste(a,b)
#define LFD 6
#define LHIGH xpaste(1.0e+, LFD)

main(){printf("%f\n", LHIGH);}

and it works correctly with gcc.

The point is that the paste macro if called through another macro will
work on macro replaced operands. I've explained this more fully in an article
which appeared in the EUUG newsletter: Macro Expansion as Defined by the
ANSI/ISO Draft Standard, Volume 8, No 2, Summer 1988.
Cornelia Boldyreff
Department of Computer Science
Brunel University
Uxbridge UB8 3PH, ENGLAND.