Jump to content
  • Advertisement
Sign in to follow this  
Andrew Russell

Pointers to static object during static init?

This topic is 5109 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
Advertisement
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!