
This makes sense. So, replacement is done after substitution on the RHS, not before macro argument substitution, correct? In other words, with #define EMPTY() #define MACRO( x ) x MACRO( EMPTY() ) would have EMPTY() substituted for the formal macro parameter x and the RHS value x. Then, a macros are executed on the RHS changing EMPTY() into nothing (literally). ----- Original Message ----- From: "Paul Mensonides" <yg-boost-users@m.gmane.org> To: <boost-users@yahoogroups.com> Sent: Tuesday, May 06, 2003 6:17 PM Subject: [Boost-Users] Re: RE: PP Library...
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
Info: <http://www.boost.org> Wiki: <http://www.crystalclearsoftware.com/cgi-bin/boost_wiki/wiki.pl> Unsubscribe: <mailto:boost-users-unsubscribe@yahoogroups.com>
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/