Topic: Alternative tokens and token pasting
Author: Martin von Loewis <loewis@informatik.hu-berlin.de>
Date: 2000/07/18 Raw View
What is the meaning of an alternative token (2.5) when occuring in
token pasting (16.3.3)? Consider
#define paste(a,b) a##b
paste(m,xor)
paste(xor,=)
Which of these has well-defined behaviour (if any), and what is that
behaviour? Which is ill-formed with required diagnostic (if any)?
2.5/2 says that the alternative token behaves as the original one
except for its spelling, and the footnote clarifies that this refers
to stringification (16.3.2). Indeed, 16.3.2 says that the #token
sequence is replaced by the spelling of the token.
16.3.3 says that the tokens are "concatenated". What does that mean in
the context of these alternative tokens?
Regards,
Martin
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: wmm@fastdial.net
Date: 2000/07/18 Raw View
In article <p6qem4umovx.fsf@informatik.hu-berlin.de>,
Martin von Loewis <loewis@informatik.hu-berlin.de> wrote:
> What is the meaning of an alternative token (2.5) when occuring in
> token pasting (16.3.3)? Consider
>
> #define paste(a,b) a##b
>
> paste(m,xor)
> paste(xor,=)
>
> Which of these has well-defined behaviour (if any), and what is that
> behaviour? Which is ill-formed with required diagnostic (if any)?
The alternative tokens are preprocessing tokens (they're
preprocessing-op-or-punc, according to 2.12p1, which makes
them preprocessing tokens, according to 2.4). 16.3.3p3 says
that the preprocessing token preceding ## is concatenated
with the preprocessing token following the ##, and that "If
the result is not a value preprocessing token, the behavior
is undefined."
I'd take that to mean that the value of "paste(m,xor)" is
the identifier "mxor", and that "paste(xor,=)" has undefined
behavior.
--
William M. Miller, wmm@fastdial.net
Vignette Corporation (www.vignette.com)
Sent via Deja.com http://www.deja.com/
Before you buy.
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]