A bit of background . I worked on some data conversion from C
to C#
using C++/CLI
midlayer, and I noticed a peculiarity in the way the debugger shows floats
and doubles
, depending on which DLL the code is executing (see code and images below). At first I thought that this was due to controlled / unmanaged differences, but then I realized that if I completely left the layer C#
and used only unmanaged data types, the same behavior was shown.
Test case . To continue exploring the problem, I created an isolated test case to clearly identify strange behavior. I assume that anyone who can test this code already has a working solution and dllimport
/ dllexport
/ macros installed . My called DLL_EXPORT
. If you need a minimal working header file let me know. Here the main application is located in C
and calls the function from the dll C++/CLI
. I am using Visual Studio 2015 , and both assemblies 32 bit
.
I'm a little worried, as I'm not sure if this is what I need to worry about, or what the debugger is doing (I'm leaning toward the latter). And frankly, I'm just frank about what is happening here.
Question: Can someone explain the observed behavior, or at least point me in the right direction?
C - Call Function
void floatTest()
{
float floatValC = 42.42f;
double doubleValC = 42.42;
float retFloat = 42.42f;
double retDouble = 42.42;
int sizeOfFloatC = sizeof(float);
int sizeOfDoubleC = sizeof(double);
floatTestCPP(floatValC, doubleValC, &retFloat, &retDouble);
sizeOfFloatC = sizeOfFloatC + sizeOfDoubleC;
}
C ++ / CLI Header
DLL_EXPORT void floatTestCPP(float floatVal, double doubleVal,
float *floatRet, double *doubleRet);
C ++ / CLI Source
void floatTestCPP(float floatVal, double doubleVal, float *floatRet, double *doubleRet)
{
float floatLocal = floatVal;
double doubleLocal = doubleVal;
int sizeOfFloatCPP = sizeof(float);
int sizeOfDoubleCPP = sizeof(double);
*floatRet = 42.42f;
*doubleRet = 42.42;
floatLocal = (float)doubleLocal;
sizeOfDoubleCPP = sizeOfFloatCPP;
}
Debugger in C - breakpoint on last linefloatTest()

Debugger in C ++ / CLI - breakpoint from second to last linefloatTestCPP()
