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

David Adrien Tanguay datanguay at watmath.waterloo.edu
Mon Sep 25 01:56:44 AEST 1989


In article <470004 at gore.com> jacob at gore.com (Jacob Gore) writes:
>Can the following be achieved with "ANSI" cpp:
>
>	MtaInit()
>
>expands to
>
>	SomeNameInit()
>
>where Mta=SomeName is specified at compile-time, WITHOUT enumerating every
>possible value of Mta in an #ifdef?

#define join(a,b)  a ## b
#define join2(a,b) join( a, b )
#define MtaInit    join2( Mta, Init )

Mta can then be defined with -DMta=something. Init must not be a macro.
The join2 is there so that the Mta will get expanded.
The standard's at work, I'm not; caveat emptor.

David Tanguay



More information about the Comp.lang.c mailing list