Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old July 18th, 2007, 03:05 PM
jubelbrus
Guest
 
Posts: n/a
Default Global variable initialization

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
Default 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
Default 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

 

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles