Topic: Ahem... er... ugh... macro question
Author: "Andrei Alexandrescu" <alexandrescua@micromodeling.com>
Date: 1999/02/26 Raw View
Should this succession of two lines compile?
#define COMMENT_START /##*
COMMENT_START /**/
Thanks,
Andrei
[ 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: Larry Brasfield <larrybr@seanet.com>
Date: 1999/02/26 Raw View
Andrei Alexandrescu wrote in message <36d6cf73.0@10.1.1.65>...
>
>Should this succession of two lines compile?
>
>#define COMMENT_START /##*
>COMMENT_START /**/
No, it need not. It should produce this token sequence
/ *
This is because comments are replaced by one space
character at translation phase 3 as defined at section
2.1 of the C++ standard. Processing of ## occurs at
phase 4. There is no mention of comment removal
for any translation phase other than 3.
16.3.1 states that if the result of the ## concatenation "is
not a valid preprocessing token, the behavior is undefined."
Section 2.4 on preprocessing tokens, at paragraph 2
clearly indicates that comments are preprocessing
token separators rather than preprocessing tokens.
Paragraph 1 further indicates this, requiring that
each preprocessing token "shall have the lexical
form of a keyword, an identifier, a literal, an operator
or a punctuator."
As a practical matter, due to the semi-recursive
nature of lexical processing, (required because
of the possibility of the ## and # operators), a
comment nominally found during phase 4 will
likely also be converted to a space. But it is
foolishness to count on this. The C++ standard
does not require your code to compile.
--Larry Brasfield
Above opinions may be mine alone.
X-Replace-Address
(Humans may reply at unundered larry_br@sea_net.com )
---
[ 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 ]