|
Boost Users : |
From: Paul Mensonides (yg-boost-users_at_[hidden])
Date: 2003-05-06 17:17:26
Tanton Gibbs wrote:
> Also, I was asked by a coworker if the following would be std C++:
>
> BOOST_PP_LIST_FOR_EACH( DO_IT, BOOST_PP_EMPTY(), ARG_LIST )
>
> I said that it would not because BOOST_PP_EMPTY would be expanded
> first to nothing, which would be the same as
> BOOST_PP_LIST_FOR_EACH( DO_IT, , ARG_LIST )
> which Paul explicitly said below was non-conformant.
>
> Is this correct?
Well, not exactly, but close. This, for example, is okay:
#define EMPTY()
#define MACRO(x) x
MACRO( ) // undefined
MACRO( EMPTY() ) // okay
However, this is not:
#define MACRO_2(x) MACRO(x)
MACRO_2( EMPTY() ) // okay for MACRO_2, undefined for MACRO
The reason is relatively simple. Before the argument is inserted into the
replacement list of MACRO_2, it is macro expanded. In this case, it expands to
nothing, which yields a replacement list like this:
MACRO( )
Which is rescanned for macros to expand and consequently introduces undefined
behavior. BOOST_PP_LIST_FOR_EACH, as well as virtually every other pp-lib
primitive uses other macros, so it is never safe to do this:
BOOST_PP_SOME_MACRO( BOOST_PP_EMPTY() )
C99 explicitly allows you to pass nothing as macro argument, but it is still
undefined in C++.
Regards,
Paul Mensonides
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net