Jump to content
  • Advertisement
Sign in to follow this  

static class in dependent lib MSVC8

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

Hi, I seem to be having trouble with code like this: In a seperate static lib:
//.h file:
class Test {
	Test() {

//.cpp file:
static Test mytestclass;

And in another project (exe); make dependent on the above static lib, and run. I see nothing - any ideas as to why? (Note, it's not just having trouble with stdio, if I try anything else I get the same problems) The same code works fine in VC6. Am I doing something wrong? Thanks!

Share this post

Link to post
Share on other sites
Basically, if you don't use a global variable, the program doesn't need to construct it. In this case it seems like MSVC has decided you never use mytestclass so it doesn't bother.

Share this post

Link to post
Share on other sites
Thanks SiCrane,

Yes, I thought this was happening, but this behaviour seems to be very strangely compiler dependent. It seems VC8,Digital Mars both 'optimize' that code away, VC7 seems to randomly decide to include/exclude some static classes, and VC6 includes them all. I would have thought there would be a compiler option somehwere for it..

As you suggested, if I create another function within the file the static variables are then actually created;

.h file:
extern void hack();
.cpp file:
void hack() {;};

And call hack from the main program - it will cause the static objects to be constructed..

Anyone have any better/ideas solutions than this?


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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!