Would you suppose that the compiler+linker is sufficiently fine to call c_Log constructor for object Log and after the constructor for Sem or , as they are in different modules, the compiler+linker gives errors or does not garauntee the correct order in constructor callings?

thank you

09-17-2008

matsp

I do not think you can rely on Log being constructed before Sem.

Log looks like something that could be implemented using a Singleton pattern, so you may not need a constructor as such.

--
Mats

09-17-2008

mynickmynick

Quote:

Originally Posted by matsp

I do not think you can rely on Log being constructed before Sem.

Log looks like something that could be implemented using a Singleton pattern, so you may not need a constructor as such.

--
Mats

What is a singleton pattern?
Log is a cyclic buffer where to write by multiple threads, which periodically is saved to a log file or sent via socket to a client log

09-17-2008

matsp

google gives this: http://en.wikipedia.org/wiki/Singleton_pattern
which is a much more complete explanation than what I can give. (But in short, it is an object that may have may instances that is represented behind the scenes by a single object).

--
Mats

09-17-2008

CornedBee

There's no guaranteed order of initialization between globals of different modules.

09-17-2008

matsp

Quote:

Originally Posted by CornedBee

There's no guaranteed order of initialization between globals of different modules.

So, presumably the two global objects could be put in a "globals.cpp" or "main.cpp" and the order of the objects themselves would define the order of initialization.

This is of course not a very natural way to solve the problem, but it IS a possibility - the biggest problem comes when you have hundreds of different modules with various global objects, in which case wrapping the object into something that can perform it's initialization as needed is the right solution, such as the singleton pattern. [There are other solutions that do similar things, but they all rely on "if this is not set, create an object, else return the existing object"].