Topic: Valid preprocessing tokens during token pasting
Author: Edward Diener <eldiener@tropicsoft.invalid>
Date: Wed, 9 Mar 2011 08:13:01 CST Raw View
If in a macro I try to past together some name ending in '::' and a
C++ identifier, I am told ( by gcc 4.5.2 ):
'error: pasting "::" and "some_cpp_entity" does not give a valid
preprocessing token.'
This seems odd to me since an identifier of the form of:
some_namespace::some_cpp_entity
is quite common in C++, so it seems very strange that the preprocessor
does not accept such token pasting given how common such an expression
is.
Can someone please cite for me the area of the standard which states
that this form of token pasting is illegal, and tell me why the
preprocessor does not accept it as part of token pasting despite its
prevalence in C++ ?
--
[ comp.std.c++ is moderated. To submit articles, try posting with your ]
[ newsreader. If that fails, use mailto:std-cpp-submit@vandevoorde.com ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Author: Edward Diener <eldiener@tropicsoft.invalid>
Date: Wed, 9 Mar 2011 10:21:48 CST Raw View
On 3/9/2011 9:13 AM, Edward Diener wrote:
>
> If in a macro I try to past together some name ending in '::' and a
> C++ identifier, I am told ( by gcc 4.5.2 ):
>
> 'error: pasting "::" and "some_cpp_entity" does not give a valid
> preprocessing token.'
>
> This seems odd to me since an identifier of the form of:
>
> some_namespace::some_cpp_entity
>
> is quite common in C++, so it seems very strange that the preprocessor
> does not accept such token pasting given how common such an expression
> is.
>
> Can someone please cite for me the area of the standard which states
> that this form of token pasting is illegal, and tell me why the
> preprocessor does not accept it as part of token pasting despite its
> prevalence in C++ ?
I can see where I do not have to use preprocessor pasting ( ## ) but can
just place a token ending with "::" next to a macro generating a C++
identifer without any preprocessor problems, so this question need not
be answered.
--
[ comp.std.c++ is moderated. To submit articles, try posting with your ]
[ newsreader. If that fails, use mailto:std-cpp-submit@vandevoorde.com ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Author: "Kenneth 'Bessarion' Boyd" <zaimoni@zaimoni.com>
Date: Sat, 12 Mar 2011 09:25:53 CST Raw View
On Mar 9, 8:13 am, Edward Diener <eldie...@tropicsoft.invalid> wrote:
> If in a macro I try to past together some name ending in '::' and a
> C++ identifier, I am told ( by gcc 4.5.2 ):
>
> 'error: pasting "::" and "some_cpp_entity" does not give a valid
> preprocessing token.'
>
> This seems odd to me since an identifier of the form of:
>
> some_namespace::some_cpp_entity
>
> is quite common in C++,
No, some_namespace::some_cpp_entity is not an identifier. That is two
identifiers separated by the scope operator :: . The recent C++0X
draft standards are publicly available as PDF.
That that denotes a single object or function, is noticed much later
in the theoretical phases of translation than preprocessing.
> so it seems very strange that the preprocessor
> does not accept such token pasting given how common such an expression
> is.
As required by the definition of ## [cpp.concat, 16.3.3 in recent C+
+0X draft standards which are publicly available]: the result of
concatenating two preprocessing tokens must be a valid preprocessing
token.
As for "why": this behavior is straight from from C90. I'm unfamiliar
with the history of standardization of C90, so don't have a proper
answer at hand.
--
[ comp.std.c++ is moderated. To submit articles, try posting with your ]
[ newsreader. If that fails, use mailto:std-cpp-submit@vandevoorde.com ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]