Global variable initialization

J

jubelbrus

Is it possible to initialize a global variable before any other global
variables is initialized.

Currently I have a binary thats linked with some dlls and by reading a
lot on the internet I've come up with this:

#pragma init_seg(compiler)
class init_before_other_globals {

}my_object;

This works fine if I have just a binary that is not linked with dlls.
my_object is initialized before anything else and everything works.
The problem is when I link this binary with some dlls. All or some of
the globals in the dll is initialized before mine. Is there any way to
prevent this from happening. I need my class to be initialized first.

Thanks for any replies
 
J

John Harrison

jubelbrus said:
Is it possible to initialize a global variable before any other global
variables is initialized.

No, impossible.

Now, suppose there was a way. What would happen if you applied this
magical technique to two global variables at the same time? See the problem!

What you really need to do is ask *why* you need one particular global
variable initialised before all others. The answer to your problem will
come when you realise that you probably don't need to do that.

john
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,996
Messages
2,570,237
Members
46,825
Latest member
VernonQuy6

Latest Threads

Top