[preprocessor] Strange BOOST_PP_CAT behavior

Hello All, Compilator: VC++ 8.0 Library version: 1.34 I can't understand problem with code like this: #define SOME_SEQ (1)(2)(3) #define BAR_MACRO_1(S) BOOST_PP_SEQ_ENUM(BOOST_PP_SEQ_TAIL(S)) #define FOO_MACRO(S) BOOST_PP_CAT(BAR_MACRO_, BOOST_PP_SEQ_HEAD(S) ## (S)) FOO_MACRO(SOME_SEQ) After preprocessing it looks like BOOST_PP_CAT(BOOST_PP_SEQ_ENUM_, BOOST_PP_CAT(BOOST_PP_SEQ_SIZE_, BOOST_PP_SEQ_SIZE_2)) (2)(3) If I replace BOOST_PP_CAT with my own macro: #define MY_CAT(a, b) MY_CAT_I(a, b) #define MY_CAT_I(a, b) a ## b Everything is all right after preprocessing: 2, 3 Why? What is wrong? -- Best Regards, Sergey mailto:flex_ferrum@artberg.ru

Sergey wrote:
I can't understand problem with code like this:
#define SOME_SEQ (1)(2)(3) #define BAR_MACRO_1(S) BOOST_PP_SEQ_ENUM(BOOST_PP_SEQ_TAIL(S)) #define FOO_MACRO(S) BOOST_PP_CAT(BAR_MACRO_, BOOST_PP_SEQ_HEAD(S) ##
(S)) ^ Are you missing a 1?
FOO_MACRO(SOME_SEQ)
After preprocessing it looks like BOOST_PP_CAT(BOOST_PP_SEQ_ENUM_, BOOST_PP_CAT(BOOST_PP_SEQ_SIZE_, BOOST_PP_SEQ_SIZE_2)) (2)(3)
If I replace BOOST_PP_CAT with my own macro:
#define MY_CAT(a, b) MY_CAT_I(a, b) #define MY_CAT_I(a, b) a ## b
Everything is all right after preprocessing: 2, 3
Why? What is wrong?
-- Best Regards, Sergey mailto:flex_ferrum@artberg.ru

Hello, John. Thursday, May 8, 2008 at 1:11:06 PM you wrote: JF> Sergey wrote:
I can't understand problem with code like this:
#define SOME_SEQ (1)(2)(3) #define BAR_MACRO_1(S) BOOST_PP_SEQ_ENUM(BOOST_PP_SEQ_TAIL(S)) #define FOO_MACRO(S) BOOST_PP_CAT(BAR_MACRO_, BOOST_PP_SEQ_HEAD(S) ##
JF> (S)) JF> ^ JF> Are you missing a 1? No. '1' should be added to BAR_MACRO_ after processing BOOST_PP_CAT.
-- Best Regards, Sergey mailto:flex_ferrum@artberg.ru

Are you missing a 1? No. '1' should be added to BAR_MACRO_ after processing BOOST_PP_CAT.
Ok, I am no expert at preprocessor so it is easy to get confused :) Have you tried: #define FOO_MACRO(S) BOOST_PP_CAT(BAR_MACRO_, BOOST_PP_SEQ_HEAD(S))(S) That looks more straightforward to me. -- JOhn

Hello, John. Thursday, May 8, 2008 at 1:47:23 PM you wrote:
Are you missing a 1? No. '1' should be added to BAR_MACRO_ after processing BOOST_PP_CAT.
JF> Ok, JF> I am no expert at preprocessor so it is easy to get confused :) JF> Have you tried: JF> #define FOO_MACRO(S) BOOST_PP_CAT(BAR_MACRO_, BOOST_PP_SEQ_HEAD(S))(S) JF> That looks more straightforward to me. Thanks a lot! It's much better! :) -- Best Regards, Sergey mailto:flex_ferrum@artberg.ru

Sergey wrote:
JF> #define FOO_MACRO(S) BOOST_PP_CAT(BAR_MACRO_, JF> BOOST_PP_SEQ_HEAD(S))(S)
JF> That looks more straightforward to me. Thanks a lot! It's much better! :)
One thing I do know about the preprocessor library is that recursion is not allowed. You can tell that Boost.Preprocessor is using BOOST_PP_CAT internally because it shows up in the preprocessed results (this happened to me before). That behavior is documented at http://www.boost.org/doc/libs/1_35_0/libs/preprocessor/doc/index.html I did a little search and I think your culprit is in boost\preprocessor\seq\enum.hpp:28: # define BOOST_PP_SEQ_ENUM(seq) BOOST_PP_CAT(BOOST_PP_SEQ_ENUM_, BOOST_PP_SEQ_SIZE(seq)) seq Since PP_CAT in the first version expanded to BAR_MACRO_1(S), the preprocessor expanded it which invokes PP_CAT again. By putting the sequence outside of the PP_CAT macro, it just expanded to BAR_MACRO_1 -- no parenthesis -- and therefor it was not expanded inside PP_CAT macro, and we were safe. Since your own macro was not PP_CAT, there was no recursion in yours and apparently everything worked. At least I think that is what happened :) -- John

Hello, John. Thursday, May 8, 2008 at 2:24:56 PM you wrote: JF> Since PP_CAT in the first version expanded to BAR_MACRO_1(S), the JF> preprocessor expanded it which invokes PP_CAT again. JF> By putting the sequence outside of the PP_CAT macro, it just expanded JF> to BAR_MACRO_1 -- no parenthesis -- and therefor it was not expanded JF> inside PP_CAT macro, and we were safe. JF> Since your own macro was not PP_CAT, there was no recursion in yours and JF> apparently everything worked. JF> At least I think that is what happened :) Yes. I think so too. John, thanks a lot for such extended explanation! You really help me. -- Best Regards, Sergey mailto:flex_ferrum@artberg.ru

Hello, I'm using the following code to trace the time different sections of code take to execute (where btime = boost::posix_time): btime::to_iso_extended_string( btime::microsec_clock::universal_time() ) I am finding that a lot of things are happening simultaneously (or rather in the same micro second) and then some random operation (perhaps the declaration of a variable, perhaps a DB query) will take 0.015 (ish) seconds. The software is running on windows XP service pack 2. Is there a known resolution issue using the microsec_clock on windows xp? Will using a boost time period have the same issue? Thanks in advance, Patrick ****************************************************************************** "This message and any attachments are solely for the intended recipient and may contain confidential and privileged information. If you are not the intended recipient, any disclosure, copying, use, or distribution of the information included in this message and any attachments is prohibited. If you have received this communication in error, please notify us by reply e-mail and immediately and permanently delete this message and any attachments. Thank you." Interactive Transaction Solutions Ltd (2473364 England) Registered Office: Systems House, Station Approach Emsworth PO10 7PW ********************************************************************** Ce message �lectronique contient des informations confidentielles � l'usage unique des destinataires indiqu�s, personnes physiques ou morales. Si vous n'�tes pas le destinataire voulu, toute divulgation, copie, ou diffusion ou toute autre utilisation de ces informations, est interdite. Si vous avez re�u ce message �lectronique par erreur, nous vous remercions d'en avertir son exp�diteur imm�diatement par email et de d�truire ce message ainsi que les �l�ments attach�s. Interactive transaction Solutions SAS- France (RCS Pontoise : 489 397 877) Si�ge social : Parc Saint Christophe, 10, Avenue de l�Entreprise 95865 Cergy-Pontoise Cedex ______________________________________________________________________ This email has been scanned by the MessageLabs Email Security System. For more information please visit http://www.messagelabs.com/email ______________________________________________________________________

"Patrick Loney" <Patrick.Loney@InteractiveTS.com> writes:
I'm using the following code to trace the time different sections of code take to execute (where btime = boost::posix_time):
btime::to_iso_extended_string( btime::microsec_clock::universal_time() )
I am finding that a lot of things are happening simultaneously (or rather in the same micro second) and then some random operation (perhaps the declaration of a variable, perhaps a DB query) will take 0.015 (ish) seconds.
The software is running on windows XP service pack 2.
Is there a known resolution issue using the microsec_clock on windows xp?
Windows reports times to a precision of 100ns, but typically the system clock has a resolution of about 10-15ms, so it is common to see 10-15ms jumps in the time. Windows Multimedia timers can give you a time period of 1ms if your hardware supports it. The only other alternative is QueryPerformanceCounter, which has a system-specific frequency (which you can get from QueryPerformanceFrequency). Some system device drivers have a bug which means QueryPerformanceCounter values vary between CPUs, and are therefore unreliable for really high precision timing unless you set the processor affinity for the thread. Anthony -- Anthony Williams | Just Software Solutions Ltd Custom Software Development | http://www.justsoftwaresolutions.co.uk Registered in England, Company Number 5478976. Registered Office: 15 Carrallack Mews, St Just, Cornwall, TR19 7UL

In this case it is the resolution of the windows timer... Patrick Loney schrieb:
Hello,
I'm using the following code to trace the time different sections of code take to execute (where btime = boost::posix_time):
btime::to_iso_extended_string( btime::microsec_clock::universal_time() )
I am finding that a lot of things are happening simultaneously (or rather in the same micro second) and then some random operation (perhaps the declaration of a variable, perhaps a DB query) will take 0.015 (ish) seconds.
The software is running on windows XP service pack 2.
Is there a known resolution issue using the microsec_clock on windows xp? Will using a boost time period have the same issue?
Thanks in advance, Patrick
******************************************************************************
"This message and any attachments are solely for the intended recipient and may contain confidential and privileged information. If you are not the intended recipient, any disclosure, copying, use, or distribution of the information included in this message and any attachments is prohibited. If you have received this communication in error, please notify us by reply e-mail and immediately and permanently delete this message and any attachments. Thank you."
Interactive Transaction Solutions Ltd (2473364 England)
Registered Office: Systems House, Station Approach Emsworth PO10 7PW
**********************************************************************
Ce message électronique contient des informations confidentielles à l'usage unique des destinataires indiqués, personnes physiques ou morales. Si vous n'êtes pas le destinataire voulu, toute divulgation, copie, ou diffusion ou toute autre utilisation de ces informations, est interdite. Si vous avez reçu ce message électronique par erreur, nous vous remercions d'en avertir son expéditeur immédiatement par email et de détruire ce message ainsi que les éléments attachés.
Interactive transaction Solutions SAS- France (RCS Pontoise : 489 397 877)
Siège social : Parc Saint Christophe, 10, Avenue de l’Entreprise 95865 Cergy-Pontoise Cedex
______________________________________________________________________ This email has been scanned by the MessageLabs Email Security System. For more information please visit http://www.messagelabs.com/email ______________________________________________________________________
------------------------------------------------------------------------
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
participants (5)
-
Anthony Williams
-
Hansi
-
John Femiani
-
Patrick Loney
-
Sergey Sadovnikov