Connecting Tech Pros Worldwide Forums | Help | Site Map

Global variable initialization

jubelbrus
Guest
 
Posts: n/a
#1: Jul 18 '07
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


Victor Bazarov
Guest
 
Posts: n/a
#2: Jul 18 '07

re: Global variable initialization


jubelbrus wrote:
Quote:
Is it possible to initialize a global variable before any other global
variables is initialized.
How often are you planning on asking the same question?
Quote:
[..]

John Harrison
Guest
 
Posts: n/a
#3: Jul 18 '07

re: Global variable initialization


jubelbrus wrote:
Quote:
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

Closed Thread