M
Matthew
Hello,
I have an executable that is calling a DLL I have built. The DLL
requires two static libraries to run (genuine statics as opposed to
the 'stub' .lib files that still require a DLL).
In the DLL source I have the following code...
{
char *l_H = (char *)malloc(200);
sprintf(l_H, "Hello");
namespace1::namespace2::namespace3::Thing l_Thing;
free(l_H);
}
....now the strange thing is that after executing the initialization of
l_Thing, l_H has been set to NULL (0x00000000).
I have a breakpoint that is triggered when free(l_H) is reached (I
know for a fact that the free() has not yet executed as VC++
breakpoints are triggered before a line of code is processed. Also I
have had other lines of code between free() and the initialization of
Thing - not shown here - where I see l_H has been reset). Also, l_H is
not going out of scope before the free() is reached.
l_H is local and Thing knows nothing about it. The constructor of
Thing is as follows (in .cpp file)...
namespace namespace1
{
namespace namespace2
{
namespace namespace3
{
Thing::Thing()
{
m_D = 0;
}
...other code ...
}
}
}
....where m_D is declared as a double with private access in the header
file.
Observations
------------
- I declare m_D as an int, the code behaves as expected (i.e. "Hello"
remains in l_H after the initialization of Thing).
- If I remove m_D = 0 from the constructor of Thing, the code works
normally
- If I declare a double and assign it a value in the main code (after
removing m_D = 0 from the Thing constructor) after the initialization
of Thing, the code works as normal.
I am posting this in microsoft.public.vc.language and comp.lang.c++ as
I am not sure whether it's a Microsoft thing or a C++ issue.
Can anyone explain this?
Thanks,
Matthew
I have an executable that is calling a DLL I have built. The DLL
requires two static libraries to run (genuine statics as opposed to
the 'stub' .lib files that still require a DLL).
In the DLL source I have the following code...
{
char *l_H = (char *)malloc(200);
sprintf(l_H, "Hello");
namespace1::namespace2::namespace3::Thing l_Thing;
free(l_H);
}
....now the strange thing is that after executing the initialization of
l_Thing, l_H has been set to NULL (0x00000000).
I have a breakpoint that is triggered when free(l_H) is reached (I
know for a fact that the free() has not yet executed as VC++
breakpoints are triggered before a line of code is processed. Also I
have had other lines of code between free() and the initialization of
Thing - not shown here - where I see l_H has been reset). Also, l_H is
not going out of scope before the free() is reached.
l_H is local and Thing knows nothing about it. The constructor of
Thing is as follows (in .cpp file)...
namespace namespace1
{
namespace namespace2
{
namespace namespace3
{
Thing::Thing()
{
m_D = 0;
}
...other code ...
}
}
}
....where m_D is declared as a double with private access in the header
file.
Observations
------------
- I declare m_D as an int, the code behaves as expected (i.e. "Hello"
remains in l_H after the initialization of Thing).
- If I remove m_D = 0 from the constructor of Thing, the code works
normally
- If I declare a double and assign it a value in the main code (after
removing m_D = 0 from the Thing constructor) after the initialization
of Thing, the code works as normal.
I am posting this in microsoft.public.vc.language and comp.lang.c++ as
I am not sure whether it's a Microsoft thing or a C++ issue.
Can anyone explain this?
Thanks,
Matthew