Connecting Tech Pros Worldwide Help | Site Map

Global variable initialization

  #1  
Old July 18th, 2007, 03:05 PM
jubelbrus
Guest
 
Posts: n/a
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

  #2  
Old July 18th, 2007, 03:05 PM
Victor Bazarov
Guest
 
Posts: n/a

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:
[..]

  #3  
Old July 18th, 2007, 07:55 PM
John Harrison
Guest
 
Posts: n/a

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Global structure variable initialization koffee answers 4 December 14th, 2007 04:45 PM
Initialize global variable before any other global variables jubelbrus answers 4 July 20th, 2007 02:15 PM
Global variable initialization using LIB project Marco Segurini answers 0 November 17th, 2005 02:15 PM
Why can't I initialize a global variable to NULL? moxm answers 19 November 15th, 2005 02:00 AM