[units] - BOOST_UNITS_STATIC_CONSTANT

It would appear that there's something wrong with this macro. I've looked at it and I'm not sure how it happens... In a precompiled header I'm including a system of units I'm creating. Some are simply composites of fundamental dimensions that are missing, such as volumetric flow, but others are different dimensions, such as currency. Some of the files that include this precompiled header use time(), the C function. However, if I use BOOST_UNITS_STATIC_CONSTANT to instantiate the unit for currency, which I'm pasting below, with VC++ 8, it pulls the time dimension into the global namespace. This of course causes the whole project to fail since that's where time() lives. If I just create a static variable this doesn't happen. What was the problem with static variables that necessitates a BOOST_UNITS_STATIC_CONSTANT? I'm using the mcs units from the vault, has this problem been fixed or even noticed before? Is there a report of changes to mcs that I can view? #pragma once #include <boost/units/systems/si.hpp> namespace esi { namespace units { using namespace boost::units; namespace systems { namespace SI { using namespace boost::units::SI; struct currency_tag : ordinal<11> {}; // dimension tag for currency typedef fundamental_dimension<currency_tag>::type currency_type; typedef unit<currency_tag, SI::system> currency; //BOOST_UNITS_STATIC_CONSTANT(coin, currency); static currency const coin; } } } }

AMDG Noah Roberts <roberts.noah <at> gmail.com> writes:
It would appear that there's something wrong with this macro. I've looked at it and I'm not sure how it happens...
<snip>
What was the problem with static variables that necessitates a BOOST_UNITS_STATIC_CONSTANT?
A static variable will be different in every translation unit. That can cause a technical ODR violation.
I'm using the mcs units from the vault, has this problem been fixed or even noticed before? Is there a report of changes to mcs that I can view?
It hasn't been noticed before. I'm pretty sure it's a compiler bug. I'll try to fix it today. You can view the current version at http://svn.boost.org/trac/boost/browser/sandbox/units or svn checkout http://svn.boost.org/svn/boost/sandbox/units In Christ, Steven Watanabe
participants (2)
-
Noah Roberts
-
Steven Watanabe