RE: [Boost-Users] newbie Question about the macro BOOST_JOIN
From: zhangwusheng [mailto:yg-boost-users@m.gmane.org]
Hi,all, In file suffix.hpp there are lines:
#define BOOST_JOIN( X, Y ) BOOST_DO_JOIN( X, Y ) #define BOOST_DO_JOIN( X, Y ) BOOST_DO_JOIN2(X,Y) #define BOOST_DO_JOIN2( X, Y ) X##Y
why donot we define such macro instead: #define BOOST_JOIN( X, Y ) X##Y
The idea behind BOOST_JOIN is to force the preprocessor to scan the macro parameters for replacement before merging the results with ##. So, it changes the meaning if one of the parameters is a macro: #define Z_BOOST_JOIN(X, Y) X##Y Z_BOOST_JOIN(id_, __LINE__) // Expands to "id___LINE__" BOOST_JOIN(id_, __LINE__) // Expands to "id_13" if __LINE__ is 13 However, I'm not sure why BOOST_DO_JOIN2 is used; it seems to me that only one layer of indirection should work. I assume it's to work around some compiler's non-conforming preprocessor. -Steve
On Fri, 27 Sep 2002 scleary@jerviswebb.com wrote:
From: zhangwusheng [mailto:yg-boost-users@m.gmane.org]
Hi,all, In file suffix.hpp there are lines:
#define BOOST_JOIN( X, Y ) BOOST_DO_JOIN( X, Y ) #define BOOST_DO_JOIN( X, Y ) BOOST_DO_JOIN2(X,Y) #define BOOST_DO_JOIN2( X, Y ) X##Y
why donot we define such macro instead: #define BOOST_JOIN( X, Y ) X##Y
The idea behind BOOST_JOIN is to force the preprocessor to scan the macro parameters for replacement before merging the results with ##. So, it changes the meaning if one of the parameters is a macro: #define Z_BOOST_JOIN(X, Y) X##Y Z_BOOST_JOIN(id_, __LINE__) // Expands to "id___LINE__" BOOST_JOIN(id_, __LINE__) // Expands to "id_13" if __LINE__ is 13
However, I'm not sure why BOOST_DO_JOIN2 is used; it seems to me that only one layer of indirection should work. I assume it's to work around some compiler's non-conforming preprocessor.
I believe that this is some kind of performance optimization for EDG-based preprocessors. For some reason, "delaying" a macro invocation improves performance (compile time) dramatically. Doesn't make any sense to me, but apparently, that's the way it is. I believe Paul Mensonides is the one who discovered the trick; I remember seeing him post about it a couple of months ago when he overhauled the Preprocessor library to add file iteration. He could confirm that this is true and perhaps give insight as to why. Regards, -Tom Wenisch Computer Architecture Lab Carnegie Mellon University
The idea behind BOOST_JOIN is to force the preprocessor to scan the macro parameters for replacement before merging the results with ##. So, it changes the meaning if one of the parameters is a macro: #define Z_BOOST_JOIN(X, Y) X##Y Z_BOOST_JOIN(id_, __LINE__) // Expands to "id___LINE__" BOOST_JOIN(id_, __LINE__) // Expands to "id_13" if __LINE__ is 13
However, I'm not sure why BOOST_DO_JOIN2 is used; it seems to me that only one layer of indirection should work. I assume it's to work around some compiler's non-conforming preprocessor.
I think it depends on whether BOOST_JOIN is called from another macro or not (if not you need the extra indirection), or at least I think that's the answer ;-) John Maddock http://ourworld.compuserve.com/homepages/john_maddock/index.htm
participants (3)
-
John Maddock
-
sclearyï¼ jerviswebb.com
-
Thomas Wenisch