gcc3.2 preprocessor concatenation or not on negative numbers
Hi all, Using gcc3.2 the concatenation of 1##Num where Num is negative leaves a space eg 1e#-1 --> 1e -1 as can be seen by the preprocessed output below. The only way round it that I can see is to simply not use a macro for this compiler Is there a preprocessor workaround for this problem? Is this even the correct behaviour? Any help appreciated. #define POW_EVAL(Num, Float_type)\ template <>\ struct pow_eval< \ Float_type BOOST_PP_COMMA() Num BOOST_PP_COMMA()\ 1 BOOST_PP_COMMA() false\ >{\ enum{ required = true};\ typedef Float_type result_type;\ result_type operator()()const\ { result_type result\ = static_cast< Float_type > (1e ## Num);\ return result;\ }\ }; POW_EVAL(-60, double) POW_EVAL(-59, double) POW_EVAL(58, double) POW_EVAL(57, double) // preprocessor output template <> struct pow_eval< double , -60 , 1 , false >{ enum{ required = true}; typedef double result_type; result_type operator()()const { result_type result = static_cast< double > (1e- 60); return result; } }; template <> struct pow_eval< double , -59 , 1 , false >{ enum{ required = true}; typedef double result_type; result_type operator()()const { result_type result = static_cast< double > (1e- 59); return result; } }; template <> struct pow_eval< double , 58 , 1 , false >{ enum{ required = true}; typedef double result_type; result_type operator()()const { result_type result = static_cast< double > (1e58); return result; } }; template <> struct pow_eval< double , 57 , 1 , false >{ enum{ required = true}; typedef double result_type; result_type operator()()const { result_type result = static_cast< double > (1e57); return result; } }; regards Andy Little
-----Original Message----- From: boost-users-bounces@lists.boost.org [mailto:boost-users-bounces@lists.boost.org] On Behalf Of Andy Little
Using gcc3.2 the concatenation of 1##Num where Num is negative leaves a space eg 1e#-1 --> 1e -1 as can be seen by
You aren't attempting to concatenate 1e and -1; you're attempting to concatenate 1e and -. I.e. token pasting is only operating on the two adjacent preprocessing tokens... <1e> ## <-> <1> The result of this *should* be <1e-> <1> ...because 1e- is a valid pp-number. However, it should not be <le-1>. To make that, you'd have to first paste on the <->, then paste on the other number: #define CAT(a, b) PRIMITIVE_CAT(a, b) #define PRIMITIVE_CAT(a, b) a ## b CAT(CAT(1e, -), 1) This works for me (as it should) on gcc3.4.4. I can't speak for gcc3.2. Regards, Paul Mensonides
"Paul Mensonides" wrote
You aren't attempting to concatenate 1e and -1; you're attempting to concatenate 1e and -. I.e. token pasting is only operating on the two adjacent preprocessing tokens...
<1e> ## <-> <1>
The result of this *should* be
<1e-> <1>
...because 1e- is a valid pp-number. However, it should not be <le-1>. To make that, you'd have to first paste on the <->, then paste on the other number:
#define CAT(a, b) PRIMITIVE_CAT(a, b) #define PRIMITIVE_CAT(a, b) a ## b
CAT(CAT(1e, -), 1)
This works for me (as it should) on gcc3.4.4. I can't speak for gcc3.2.
Thanks Paul. It works on gcc3.2, however I need to use CAT(Sign, Number) (or Just Sign ## Number) in the Macro too and then I get a bunch of warnings saying: test.cpp:25:22: warning: pasting "-" and "60" does not give a valid preprocessing token etc. regards Andy Little
-----Original Message----- From: boost-users-bounces@lists.boost.org [mailto:boost-users-bounces@lists.boost.org] On Behalf Of Andy Little
#define CAT(a, b) PRIMITIVE_CAT(a, b) #define PRIMITIVE_CAT(a, b) a ## b
CAT(CAT(1e, -), 1)
This works for me (as it should) on gcc3.4.4. I can't speak for gcc3.2.
Thanks Paul. It works on gcc3.2, however I need to use CAT(Sign, Number) (or Just Sign ## Number) in the Macro too and then I get a bunch of warnings saying:
test.cpp:25:22: warning: pasting "-" and "60" does not give a valid preprocessing token
Let me see if I'm understanding you correctly... You need to construct (e.g.) 1e-1 and also need -1 in a different spot? In the former case, you have to paste the pieces together in the order as specified above so that at all times the result is a single valid preprocessing token. In the latter case, you don't need token-pasting at all. Just say: Sign Number. Regards, Paul Mensonides
"Paul Mensonides" wrote
Let me see if I'm understanding you correctly... You need to construct (e.g.) 1e-1 and also need -1 in a different spot? In the former case, you have to paste the pieces together in the order as specified above so that at all times the result is a single valid preprocessing token. In the latter case, you don't need token-pasting at all. Just say: Sign Number.
Ooops . Sorry for making a fuss. Thanks for your patience. I'm a bit stupid unfortunately :-( regards Andy Little
-----Original Message----- From: boost-users-bounces@lists.boost.org [mailto:boost-users-bounces@lists.boost.org] On Behalf Of Andy Little
#define POW_EVAL(Num, Float_type)\ template <>\ struct pow_eval< \ Float_type BOOST_PP_COMMA() Num BOOST_PP_COMMA()\ 1 BOOST_PP_COMMA() false\
BTW, all of these BOOST_PP_COMMA()'s here are pointless. Just use commas... Float_type, Num, 1, false. BOOST_PP_COMMA is for programmatic and/or delayed comma creation. Regards, Paul Mensonides
participants (2)
-
Andy Little
-
Paul Mensonides