This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Problem with the EGCS cpp?
- To: Paul Derbyshire <pderbysh at usa dot net>
- Subject: Re: Problem with the EGCS cpp?
- From: Zack Weinberg <zack at rabi dot columbia dot edu>
- Date: Thu, 18 Feb 1999 00:39:21 -0500
- cc: egcs at egcs dot cygnus dot com
On Thu, 18 Feb 1999 00:09:55 -0500, Paul Derbyshire wrote:
>The egcs cpp seems to be causing problems with macro expansion.
>A project I am working on has a macro
>
>#define SCOPE(arg) arg
[...]
>The problem is that the cpp in the egcs 1.1.1 release is producing stuff like
>
>foo ::bar = 3;
>
>with extra spaces. I double and triple checked that there is no whitespace
>on the end of the line defining the macro; a newline immediately follows
>"arg". So the preprocessor seems to be creating extra whitespace out of
>thin air and this is causing a parse error in the macro testing code.
>
>Question #1: Is this documented behavior of cpp?
>Question #2: Is it supposed to do this?
>Question #3: If so, how do I suppress this extra whitespace?
>Question #4: If it's a bug, is there a known workaround?
It's supposed to do this, in the sense that cpp is required to prevent
accidental token concatenation from macro expansion. This
#define SCOPE(arg) arg
SCOPE(foo)bar
is not allowed to produce `foobar' in the output, it must be
`foo bar'. cccp inserts whitespace even when it's not strictly
necessary, which is allowed. cpplib does what you want; one of its
design goals is to minimize unnecessary whitespace insertion. It is
definitely unportable to rely on how much whitespace is inserted by
any preprocessor.
I'm surprised the scope resolution operator :: does not allow
whitespace on either side, since it is grammatically an operator, not
part of an identifier. This might be a bug in the C++ front end. Or
I might be demonstrating once again that I know squat about C++.
The best workaround I can come up with is
#ifdef HAVE_NAMESPACES
#define SCOPED(space, symbol) space##::##symbol
#else
#define SCOPED(space, symbol) ::##symbol
#endif
SCOPED(foo, bar) -> foo::bar or ::bar
You can't paste a token with something outside the macro body, so you
can't use the nice SCOPE(foo)::bar notation. However, this will
definitely work on all C89-compliant preprocessors.
zw