GCC Pre-processor bug?

nismo@freeuk.com nismo@freeuk.com
Tue Oct 31 10:45:00 GMT 2000


I am using gcc on RedHat linux and I seem to be experiencing a bug in the
gcc prerocessor. I am trying to use the "Concat..." macros from the "Imake"
build but I am finding that there is a fundamental instance where they fail.
I have traced this to a number of "nuances" in gcc itself.

First, the machine and gcc details:

$ uname -a
Linux <hostname> 2.2.14-5.0 #1 Tue Mar 7 21:07:39 EST 2000 i686 unknown
$ gcc -v
Reading specs from /usr/lib/gcc-lib/i386-redhat-linux/egcs-2.91.66/specs
gcc version egcs-2.91.66 19990314/Linux (egcs-1.1.2 release)

Now the problem. Please forgive me for supplying this in a possible two-
file scenario but in this form I don't have to butcher "Imake" itself...

Consider the following Imake.tmpl and Imakefile:

/************************************************** Start of Imake.tmpl */
#define Concat3(a,b,c)a/**/b/**/c

/**************************************************** End of Imake.tmpl */

/*************************************************** Start of Imakefile */
#define PathChar /

/***************************************************** End of Imakefile */

The problem is that when gcc is run with the "-traditional" flag, the output
within the resultant "Makefile" looks as follows:


which is wrong. What I'm trying to get is:


and the reason I'm not getting it is because macro expansion for parameters
of the Concat() macro is being attempted *after* the expansion of the macro
itself. Shouldn't it be done before? Is this intentional?

The definition of Imake.tmpl can be changed to the following in an attempt
to fix the problem. This fix works on some other compilers, but not on gcc:

/************************************************** Start of Imake.tmpl */
#define _Concat3(a,b,c)a##b##c
#define Concat3(a,b,c)_Concat3(a,b,c)

/***************************************************** End of Imakefile */

The idea is that a double macro invokation causes the parameters of the
original Concat() macro to be expanded before before the bucket invokation
of the _Concat() macro with identical parameters. Now when you run Imake
the Makefile contains:


which is still not correct. The reason the "/" appeared, however, was
because the sequence "PathChar" was recognisable in the intermediate stage:


However, if I butcher "Imake" and remove the "-traditional" option from the
gcc command line, we now get:


which is correct *except* for the spurious whitespace on the front. Each
macro expansion that is done generates a spurious leading whitespace! This
makes usage of this macro impossible if the expanded output of the macro
needs to start from column one.

I would appreciate any comments and details of any known workarounds, if
there are any.

Many Thanks in Advance,

Andre Sihera.

More information about the Gcc-bugs mailing list