Problem with strange macro definition
Ray Butterworth
rbutterworth at watmath.waterloo.edu
Thu Jan 26 05:00:44 AEST 1989
In article <208 at libove.UUCP>, root at libove.UUCP (Jay M. Libove) writes:
> #define awful_macro(nnnn) \
> if (x_/**/nnnn > y_/**/nnnn) z_/**/nnnn = 0
> Which causes the SCO compiler to generate errors claiming that
The trick is to put the token joining into yet another macro,
and then to use that macro in any of your own macros.
Then whenever you move to a new compiler, you need only add
more conditions to the one place to make all the other macros
work properly (if it is possible that is).
Note that the absence of spaces after commas is not simply
a matter of style.
This should work on pANS, gnu, and Reiser cpp's:
/* this part should be in a header included by all your other headers */
#if !defined(__STDC__)
# define __GLUE(x)x
# define GLUE(a,b) __GLUE(a)b
# define QUOTE(x) "x"
#else /* __STDC__ */
# define __JOIN(x)x##
# define GLUE(a,b) a##b
# define QUOTE(x) #x
#endif/* __STDC__ */
/* this part should be in your header file defining the awful_macro */
#define awful_macro(nnnn) \
if (GLUE(x_,nnnn) > GLUE(y_,nnnn)) GLUE(z_,nnnn) = 0
/* this part should be in your source file */
awful_macro(blah)
More information about the Comp.lang.c
mailing list