Boost logo

Boost :

From: Schoenborn, Oliver (Oliver.Schoenborn_at_[hidden])
Date: 2003-09-25 11:23:04


> From: David Abrahams [mailto:dave_at_[hidden]]
>
> 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.

True but what about fundamental "types", like int and pointers? I'm pretty
sure I read in Modern C++ Design that they are allocated and initialized as
soon as TU available (i.e. upon startup if static link, or as soon as dso
loaded if dynamically linked), and space available for TU lifetime:

        // SomeClass.hh
        class Foo {};
        template <typename TT>
        struct SomeClass {
            static Foo* foo;
        };
        template <typename TT>
        Foo* SomeClass<TT>::foo = NULL;

        // main.cc
        #include "SomeClass.hh"
        #include <iostream>
        int main() {
                SomeClass<bool> sc;
                // next line will ALWAYS print value of NULL to stdout:
                std::cout << (void*)sc.foo << std::endl;
        }

Oliver


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