Re: Feedback needed, especially non-Linux

al davis <[email protected]>
Newsgroups gmane.comp.gnu.gnucap.devel
Message-ID <[email protected]>
On Thursday 22 February 2007 19:15, David Fang wrote:
> > Consider this program....
> > ================
> > #include <iostream>
> > class foo {
> > public:
> >   foo() {std::cout << "Hello world\n";}
> > } x;
> >
> > int main() {}
> > ================
>
> Solution:
>
> If you need iostream facilities during global initialization
> (pre-main), you can guarantee it is set up by inserting:
>
> static const std::ios_base::Init _init;
>
> before uses of std::cout, etc...
>
> > Does it work?
> > How?

Are you telling me that it doesn't?  Ahh. ... link order 
problem.  The language spec requires this to work.  It works 
for me.

Is that Init_init documented anywhere, in the C++ standard 
document?  I did not see it in Stroustrup's book.  If not, it 
is not portable either, no improvement over the link order 
issue.  If I have 100 files like this, should I put that in all 
100 of them?  It looks like a hack..

> By the same token, it also makes sure the stream facilities
> stay alive long enough during global destruction, (some
> reference-count like mechanism) since destruction happens in
> reverse order (within each translation unit).

Destruction happens in reverse order, period.  That is, in 
reverse of the actual construction order.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.