This is the mail archive of the
gcc-prs@gcc.gnu.org
mailing list for the GCC project.
Re: preprocessor/4923: Concatenation appears to handle whitespace incorrectly
- From: 'Zack Weinberg' <zack at codesourcery dot com>
- To: nobody at gcc dot gnu dot org
- Cc: gcc-prs at gcc dot gnu dot org,
- Date: 23 Nov 2001 18:56:00 -0000
- Subject: Re: preprocessor/4923: Concatenation appears to handle whitespace incorrectly
- Reply-to: 'Zack Weinberg' <zack at codesourcery dot com>
[Get raw message]
The following reply was made to PR preprocessor/4923; it has been noted by GNATS.
From: 'Zack Weinberg' <zack@codesourcery.com>
To: "Baum, Nathan I" <s0009525@chelt.ac.uk>
Cc: gcc-gnats@gcc.gnu.org
Subject: Re: preprocessor/4923: Concatenation appears to handle whitespace incorrectly
Date: Fri, 23 Nov 2001 10:51:01 -0800
On Thu, Nov 22, 2001 at 01:47:51PM -0000, Baum, Nathan I wrote:
>
> > At that point the tokens on either side of ## are ")" and "def".
> > Pasting them together produces an invalid token,
> > ")def", which triggers undefined behavior - we choose to pretend the
> > ## never happened. Then "FOO ( abc )" gets expanded to produce "abc".
> > Since "abc" and "def" were not concatenated, cpp has to put a space
> > between them so they are interpreted sa separate tokens.
>
> Would it break existing programs if ## were to concatenate the two tokens
> regardless (in some later version of gcc)? I'd imagine that no sensible
> program would rely upon undefined behaviour, so it shouldn't. Presumeably,
> it'd have to throw the two tokens away and rescan the newly created string,
> but that doesn't _seem_ like a major problem (I don't know how CPP handles
> these things internally, so it might be).
It does, in fact, concatenate "the two tokens" in the textual output -
but the two tokens which get concatenated are ")" and "def".
Contrast
#define a(x) FOO(abc) ## x
#define b(x) FOO(abc) x
a(def) -> FOO(abc)def
b(def) -> FOO(abc) def
To do what you apparently want, when the ")" was the last character of
a macro invocation, it would have to remember that it had been pasted
after and apply the paste to the last token of the macro expansion.
This would be a lot of work and frankly I don't see the point. Show
me real code that desperately needs this functionality and I'll show
you how to fix it so it's standard conforming C.
> > gcc 3.x will warn you when this happens:
> > test.c:5:1: warning: pasting ")" and "def" does not give a valid
> preprocessing token
>
> Hmm. Shouldn't the message say 'concatenating' rather than 'pasting'?
The manual uses the two terms interchangeably, and I think the error
message is already long enough.
zw