473,378 Members | 1,522 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,378 software developers and data experts.

When does Storage allocation for static data happens?

Hi I want to know when does the storate allocation happens for member
static data? For example I have following class declared in a header

typedef void (*fptr)(void);
class DllMethods
{
public:
static int data;
static fptr function;
};
int globalData;

//In the implementation I have commented out the static data
initialization
//fptr DllMethods::function = 0;
//int DllMethods::data = 0;

If in the implementation file, I do not do the static member
initialization, then does the compiler allocates storage for the static
data or not? If it allocates space for the static data then what does
the compiler initialize them to? Are they simply left uninitialized?

Thanks,
Divick

Mar 17 '06 #1
1 2353

Divick wrote:
Hi I want to know when does the storate allocation happens for member
static data? For example I have following class declared in a header

typedef void (*fptr)(void);
class DllMethods
{
public:
static int data;
static fptr function;
};
int globalData;

//In the implementation I have commented out the static data
initialization
//fptr DllMethods::function = 0;
//int DllMethods::data = 0;

If in the implementation file, I do not do the static member
initialization, then does the compiler allocates storage for the static
data or not? If it allocates space for the static data then what does
the compiler initialize them to? Are they simply left uninitialized?

Thanks,
Divick


Static members in a class are global variables with class scope.
So you have to explicitly define the static variables outside the class
globally.
If you don't define them you will get a compilation error at the place
where you access those variables.
They are not allocated memory at all, if you do not define them outside
the class.

Regards
Sunil Varma

Mar 17 '06 #2

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

Similar topics

16
by: garyolsen | last post by:
For a class, MyClass, there are two ways to instantiate an object: 1. MyClass *MC = new MyClass(); 2. MyClass MC; In general, when should you have to use 1 and when 2? What're...
24
by: Steven T. Hatton | last post by:
In the following code, at what point is S::c fully defined? #include <iostream> using std::cout; using std::endl; using std::ostream; class C { int _v;
5
by: Matthias Kaeppler | last post by:
Hi, say I have a class X, such that: class X { A a; B b; C c; ...
7
by: cgamache | last post by:
Which is a more correct statement? A destructor runs automatically when an object is deallocated. or A destructor runs automatically immediately before an object is deallocated.
13
by: Kantha | last post by:
Hi all, I have declared an Union as follows typedef union { struct interrupt_bits { unsigned char c_int_hs_fs_status : 1, c_setup_intflag : 1,
74
by: aruna.mysore | last post by:
Hi all, I have a simple definitioin in a C file something like this. main() { char a; ....... int k; }
58
by: Jorge Peixoto de Morais Neto | last post by:
I was reading the code of FFmpeg and it seems that they use malloc just too much. The problems and dangers of malloc are widely known. Malloc also has some overhead (although I don't know what is...
5
by: kanalkannan | last post by:
Hi, I have heard a question in C data storage i want to know where the auto,static and global variables are get stored and what are the memory segments like stack heap and its allocation. ...
0
by: raylopez99 | last post by:
I ran afoul of this Compiler error CS1612 recently, when trying to modify a Point, which I had made have a property. It's pointless to do this (initially it will compile, but you'll run into...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.