//.h file:
class Test {
public:
Test() {
printf("hello??\n");
}
};
//.cpp file:
static Test mytestclass;
static class in dependent lib MSVC8
Hi,
I seem to be having trouble with code like this:
In a seperate static lib:
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!
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.
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;
eg:
And call hack from the main program - it will cause the static objects to be constructed..
Anyone have any better/ideas solutions than this?
Thanks!
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;
eg:
.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?
Thanks!
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement