| The ANSI C preprocessor has to tokenize the input stream into C language
tokens. That is it places white spaces between the recognized tokens. Hence a
concatenation with you construct isn't possible. It works with pre-ANSI
preprocessors as vaxc. This was mentioned before in this conference and the
DECC notes conference. There are also a lot of examples how to do token
concatenation with macros in ANSI C. This is done with the ## operator which is
evaluated in macro replacements. I suggest
#if __STDC__
#define _MMMDEF(a,b) a##b
#define MMMDEF(M,Z) _MMMDEF(M,Z)
#define MMM(Z) MMMDEF(M,Z)
#else
#define MMMDEF() M
#define MMM(Z) MMMDEF()Z
#endif
The additional macro is necessary to have M expanded before it is passed to the
real concatenation, the ##.
Hope this helps,
Hartmut
|
| RE .1:
> #if __STDC__
> #define _MMMDEF(a,b) a##b
> #define MMMDEF(M,Z) _MMMDEF(M,Z)
Hartmut's answer was great, but I'd add two little cautions to it:
1. The helper macro _MMMDEF should be named something else. An
identifier beginning with an underscore followed by an uppercase
letter (or another underscore) is reserved to the C language
implementation and should never by declared or defined as a macro
in a user's source code.
2. The test "#if __STDC__" is equivalent to "#if __STDC__ != 0". This
will be TRUE for a strictly-conforming compiler mode (in which it is
required that __STDC__ == 1), and also for a huge number of situations
which are undefined by the standard (where the value of the macro is
nonzero but not 1). In particular, it will be FALSE if __STDC__ is
defined with a value of 0 - but defining __STDC__ to 0 just happens
to be a relatively common practice among UNIX compilers (including
Digital UNIX and System V compilers) to indicate a relaxed-ANSI
mode, which normally means that K&R-style token pasting will not
be done. So a better test in this case would be "#if defined (__STDC__)".
|