This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Global static variables
- To: gcc mailinglist <gcc at gcc dot gnu dot org>
- Subject: Global static variables
- From: Soeren Grimm <soeren at viatronix dot net>
- Date: Fri, 18 May 2001 10:54:29 -0400
Hi,
i don't know where i exactly should ask this. By i think may be this is
the
right mailinglist.
We have a huge project with different modules. So we wanna make our own
output-stream.
Like std::out, but with special features. But for this we must somehow
ensure that there is only ONE instance of the outputstream in the whole
project.
We tried:
1.)
global.h:
static outputsteam dbg;
2.)
global.h:
extern outputstream dbg,
global.cpp:
outputstream dbg
======================
Then we include global. h in all files.
Problem of solution 1: multiple instance of dbg;
Problem of solution 2: we can't ensure that the instance is constructed
in time.
The outputstream itself could be used in constructors of other classes.
What is the right way to define something really global and only once?
Thanks in advance
regards,
Soeren