|
Boost : |
Subject: [boost] [Math.Constants] Help needed with the preprocessor
From: John Maddock (boost.regex_at_[hidden])
Date: 2011-12-16 13:23:52
Folks we have a problem: rather late in the day I've discovered that our
Math.Constants code doesn't compile on anything except VC++, and the problem
is preprocessor token pasting. So I'm hoping we have some experts around
here that can help!
The issue is we currently construct the constants from a macro invocation
such as:
BOOST_DEFINE_MATH_CONSTANT(half, 5.000000000000000000000000000000000000,
00000000000000000000000000000000000000000000000000000000000000000000000000,
-01);
But the "-01" part (the exponent) isn't a valid pp-token, so trying to
token-paste it fails on GCC (compiler error).
Does anyone know if there's a way to overcome this?
As an alternative, I've considered something like:
BOOST_DEFINE_MATH_CONSTANT(ln_two,
6.931471805599453094172321214581765680e-001,
"6.93147180559945309417232121458176568075500134360255254120680009493393621969694715605863326996418687542001481021e-001");
But this would still require token pasting of the
6.931471805599453094172321214581765680e-001
part. But is this now a valid pp-token if the "-" is internal to the token?
It works on the compilers I've tried, but I don't want to be skewered by
this again down the line....
Truly hating the preprocessor yours, John.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk