Boost logo

Boost :

From: Robert Ramey (ramey_at_[hidden])
Date: 2006-12-15 16:02:10


Emil Dotchevski wrote:

> Therefore, you are still prone to threading problems. There is
> nothing in the C++ standard which guarantees globals will be
> initialized before main().

According to the reference I use: The C++ Programming Language by Stroustrup
page 244 10.4.9:
"A global, namespace or class static object which is created once "at the
start of the program" and destroyed at once at the termination of the
program." I've always interpreted this to mean what it says and this is
reflected in the standard.. But I'm sure some else on this list can give a
definitive answer as to what the standard actually says.

As far as "deadstripping" code - this has indeed been a big problem -
especially in release mode. I've referred to it as overzealous optimization.
Compilers vary quite a bit in this regard and In practice it has been
addressed on an ad-hoc basis. In some cases code has been marked "_export"
just so the optimizer doesn't drop it. This is the function of the module
"force_include.hpp".

> In my opinion, the only portable option is to require manual
> registration,

That may well be true.

> and leave it up to the user to come up with their own,
> non-portable solution for automatic registration, and deal with
> multi-threading/deadstripping problems this could cause.

Or the user could use the system included with the serialization library
which has already dealt with these issues.

> I personally find it easier to register my
> classes "manually" (note that systems other than the serialization
> library also require class registration.)

I'm not going to disagree with that. This was the first method I used and
it works well and is portable. But the lack of an automatic method like
"export" raised a chorus of howls which had to be addressed. So now we
have both. Take your pick.

Robert Ramey


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk