By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,952 Members | 1,592 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,952 IT Pros & Developers. It's quick & easy.

When does Storage allocation for static data happens?

P: n/a
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
Share this Question
Share on Google+
1 Reply


P: n/a

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 discussion thread is closed

Replies have been disabled for this discussion.