Jump to content
  • Advertisement
Sign in to follow this  
indigox3

static member variables and DLLs

This topic is 4017 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

Say I have this: // inside A.h class MACRO_THAT_EXPANDS_TO_DLLEXPORT_OR_DLLIMPORT A { static int Temp; }; // inside A.cpp int A::Temp = 0; A gets compiled to A.dll B.dll and C.dll include A.h and use A.dll Does the code in A, B, C see the same value for A::Temp? If they are using the same heap manager? If they are using different heap managers? Not really sure how static values get shared across dll boundaries.

Share this post


Link to post
Share on other sites
Advertisement
B.dll and C.dll will both refer to A::Temp within A.dll. This also has nothing to do with the heap as the variable is statically allocated, the heap only deals with dynamically allocated objects.

Share this post


Link to post
Share on other sites
Quote:
Original post by joanusdmentia
B.dll and C.dll will both refer to A::Temp within A.dll. This also has nothing to do with the heap as the variable is statically allocated, the heap only deals with dynamically allocated objects.


It is ever possible for B and C to not have the same value of A::Temp?
Perhaps if A is compiled to a static library that is linked with B, but compiled to a dynamic library, and linked to C?

Share this post


Link to post
Share on other sites
Quote:
Original post by indigox3
Quote:
Original post by joanusdmentia
B.dll and C.dll will both refer to A::Temp within A.dll. This also has nothing to do with the heap as the variable is statically allocated, the heap only deals with dynamically allocated objects.


It is ever possible for B and C to not have the same value of A::Temp?
Perhaps if A is compiled to a static library that is linked with B, but compiled to a dynamic library, and linked to C?


In that case, B and C would see things differently

Share this post


Link to post
Share on other sites
Quote:
Original post by jbarcz1
Quote:
Original post by indigox3
Quote:
Original post by joanusdmentia
B.dll and C.dll will both refer to A::Temp within A.dll. This also has nothing to do with the heap as the variable is statically allocated, the heap only deals with dynamically allocated objects.


It is ever possible for B and C to not have the same value of A::Temp?
Perhaps if A is compiled to a static library that is linked with B, but compiled to a dynamic library, and linked to C?


In that case, B and C would see things differently


Could you describe why that is?

Also, what about if a.cpp had something like:

static int gVariable;

Would there be separate copies in B and C if A was linked as a static lib to B and as a dll to C?

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!