Concatenating with a compile-time definition in "ANSI" CPP

Karl Heuer karl at haddock.ima.isc.com
Thu Oct 5 10:13:53 AEST 1989


In article <17975 at pasteur.Berkeley.EDU> hunt at ernie.Berkeley.EDU (Jim Hunt) writes:
JH>#define MyInit(arg)   arg/**/Init

DG>[This is an accident of a bug in the Reiser cpp]

JH>Exactly, and it still works.

Yes, if you happen to be using a non-ANSI compiler with the Reiser cpp, it
works.

JH>I think this is what the ## was INVENTED for.  To make the standard conform
JH>to the existing bugs/flaws/features in most systems.

That's a strange way of putting it, since the Committee explicitly did NOT
bless the existing bug.  It recognized the need for token-pasting, and,
finding no acceptable method in current practice, invented one.

JH>[I'd prefer ##, but not all compilers are ANSI]

I'll mention once again that the Reiserism does NOT work on ANSI compilers.
Thus the correct way to do this, if you're willing to assume that you'll never
have to port to a non-ANSI non-Reiser compiler (and that __STDC__ is not set
by non-ANSI compilers!), is with something like
	#if __STDC__
	#define glue(x,y) x ## y
	#else
	#define glue(x,y) x/**/y
	#endif

>Question, what do ansi compilers do with [a comment]?

They replace it with a blank.  Pretty simple, eh?

Karl W. Z. Heuer (ima!haddock!karl or karl at haddock.isc.com), The Walking Lint



More information about the Comp.lang.c mailing list