This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Global static variables


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



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]