B
Bran Kelly
Hi,
I am running into something I haven't ever encountered before. I have a
static instance of a class declared in a cpp file, which seems to be
optimized (or for some other reason) out of existence. It is something like
the following:
foobar.hpp
class foobar
{
};
foobar.cpp
static foobar s_foobar;
This is part of larger chunk of code (a monostate factory, which relies upon
a object types (foobar) being statically initialized, but never actually
used directly. Note this code is loosely based on Dewhurst's firewall code
from "C++ Gotchas"), which works just fine when it is part of my unit test
framework, i.e. the static instance is actually created, and everything is
just great.
When I folded the code back into my app, foobar is never instantiated. At
first I thought I was dreaming, but as a quick hack I placed a plain ol' C
function in foobar.cpp that did nothing but access one of foobar's member
vars. When that function was placed in my main application code - poof -
foobar was suddenly instantiating into existence.
I am compiling with Visual Studio 8 and have only one "non-standard"
setting, which is "-Zm200", which I had to do because my pre-compiled header
file had surpassed the default size allowed.
It should also be noted that I am running in debug mode, with no
optimizations, running as vanilla as possible.
Is there some compiler setting that would cause such behavior? I have done a
diff between my unit test and my application and I could find no culprit.
TIA,
Bran
I am running into something I haven't ever encountered before. I have a
static instance of a class declared in a cpp file, which seems to be
optimized (or for some other reason) out of existence. It is something like
the following:
foobar.hpp
class foobar
{
};
foobar.cpp
static foobar s_foobar;
This is part of larger chunk of code (a monostate factory, which relies upon
a object types (foobar) being statically initialized, but never actually
used directly. Note this code is loosely based on Dewhurst's firewall code
from "C++ Gotchas"), which works just fine when it is part of my unit test
framework, i.e. the static instance is actually created, and everything is
just great.
When I folded the code back into my app, foobar is never instantiated. At
first I thought I was dreaming, but as a quick hack I placed a plain ol' C
function in foobar.cpp that did nothing but access one of foobar's member
vars. When that function was placed in my main application code - poof -
foobar was suddenly instantiating into existence.
I am compiling with Visual Studio 8 and have only one "non-standard"
setting, which is "-Zm200", which I had to do because my pre-compiled header
file had surpassed the default size allowed.
It should also be noted that I am running in debug mode, with no
optimizations, running as vanilla as possible.
Is there some compiler setting that would cause such behavior? I have done a
diff between my unit test and my application and I could find no culprit.
TIA,
Bran