Boost logo

Boost :

From: Alexander Nasonov (alnsn-mycop_at_[hidden])
Date: 2003-09-25 02:49:02

David Abrahams wrote:

> Alexander Nasonov <alnsn-mycop_at_[hidden]> writes:
>> Any interest in static_list class?
> It's a nice idea to formalize this. I've used the idiom in the past.
> The one *major* problem with it is that a translation unit's static
> initialization is not required to happen until such time as some
> function in that translation unit is invoked. The result is that you
> can't simply link together TUs which contain some class description
> and the associated registration object, and expect the registration to
> happen.

// Translation_unit_1.cpp
#include "static_list.hpp"
static_list<char const*>::insert filename1("Translation_unit_1.cpp");

// Translation_unit_2.cpp
#include "static_list.hpp"
static_list<char const*>::insert filename2("Translation_unit_2.cpp");

Both translation units include static_list.hpp. Later, when you call
static_list<char const*>::begin you are calling it as a function defined
inline in both translation units. At least yesterday it was my argument
against this paragraph in standard:

3.6.2 / 3
It is implementation defined whether or not the dynamic initialization (8.5,
9.4, 12.1, 12.6.1) of an object of namespace scope is done before the first
statement of main. If the initialization is deferred to some point in time
after the first statement of main, it shall occur before the first use of
any function or object defined in the same translation unit as the object
to be initialized.31) [Example:

3.7.1 / 2
If an object of static storage duration has initialization or a destructor
with side effects, it shall not be eliminated even if it appears to be
unused, except that a class object or its copy may be eliminated as
specified in 12.8.

Ctor of static_list<char const*>::insert has side effect. It modifies
static_list<char const*>::m_head and static_list<char const*>::m_size.
Later or sooner it should be called.

> Ultimately, to be reliable, you need explicit calls to initialization
> functions :(, which makes this technique much less useful than it
> could be.

I still hope that static_list<char const*>::begin is enough. I should check
where inline functions are defined, though.

Alexander Nasonov
Remove minus and all between minus and at from my e-mail for timely response

Boost list run by bdawes at, gregod at, cpdaniel at, john at