Sign in to follow this  

Pointers to static object during static init?

This topic is 4748 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Quick question: Say I need to store away a pointer to a static object in another static object. I do not need to actually use that pointer until well after static initialization. The question is - will that pointer be(come) valid, even if the static object has not yet been constructed? I'm under the impression that they are valid, but I need to know for sure.

Share this post


Link to post
Share on other sites
Acquiring the pointer itself should be fine, provided you only use static type information to get the pointer (no dynamic_casts).

Share this post


Link to post
Share on other sites
I'm pretty sure it'll be fine. It's just a pointer, and the memory for the static object is reserved when the linker is executed. Therefore it's only a matter of whether the linker will allocate the static before the other struct is given the address of it. I think that if this wasn't going to work then you'd know when you get a linker error.

Share this post


Link to post
Share on other sites

This topic is 4748 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this