473,406 Members | 2,847 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

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

Jul 18 '07 #1
2 1892
jubelbrus wrote:
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?
[..]

Jul 18 '07 #2
jubelbrus wrote:
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

Jul 18 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: jose luis fernandez diaz | last post by:
Hi, I am reading Stroustrup's book 'C++ Programming Language'. In the 10.4.9 section (Nonlocal Store) he says: "A variable defined outside any function (that is global, namespace, and class...
4
by: ypjofficial | last post by:
Pls look at this code ////////////////////start/////////// class a { public: a(){ cout<<"inside constructor of a"<<endl; } int b()
8
by: lawrence | last post by:
I'm learning Javascript. I downloaded a script for study. Please tell me how the variable "loop" can have scope in the first function when it is altered in the second function? It is not defined...
33
by: MLH | last post by:
I've read some posts indicating that having tons of GV's in an Access app is a bad idea. Personally, I love GVs and I use them (possibly abuse them) all the time for everything imaginable - have...
3
by: Rahul Gandhi | last post by:
Hi, Which one preferable with respect to code size of the executable Un-initialised global variables or initialised global variables regards Rahul
12
by: jyu.james | last post by:
I'm trying to detect reads of uninitialized global variables (that are declared in one file, and used in another as an extern). I know that ANSI C initializes all global variables to 0, however,...
10
by: n.torrey.pines | last post by:
Are global variables (and const's) guaranteed to be initialized before static class members (and methods) ? const int x = 19907; int get_x() { return x; } // another compilation unit: ...
9
by: Ed Jensen | last post by:
I'm having a vexing problem with global variables in Python. Please consider the following Python code: #! /usr/bin/env python def tiny(): bar = for tmp in foo: bar.append(tmp) foo = bar
1
weaknessforcats
by: weaknessforcats | last post by:
C++: The Case Against Global Variables Summary This article explores the negative ramifications of using global variables. The use of global variables is such a problem that C++ architects have...
4
by: koffee | last post by:
Hi people, I've got a question on global structure initialization. A global variable like int can be explicitly initialized as: int Global = 1; But how can I explicitly initialize a...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.