Porting from VS6 to VS2012: return values screwed up

141 views Asked by At

While porting a VS6 project to VC++2012 environment, I'm experiencing a strange behavior...

Let's say I've the following

// double AreaIco = 75.0;
// double theApp.m_GlobalScale = 0.25;
double ToLong(double); // elsewhere defined
double result = ToLong(AreaIco * theApp.m_GlobalScale * theApp.m_GlobalScale);

What I find is that the ToLong function gets "0" as input parameter

This also happens if I try to introduce temporary variables:

double temp1 = AreaIco * theApp.m_GlobalScale;
double temp2 = temp1 * theApp.m_GlobalScale;
AreaIcoInScala = ToLong(temp2);

Both temp1 and temp2 evaluate to either 0 or a denormalized value.

However, trying to evaluate the expression in QuickWatch returns correct value.

Does anyone have any clue for such a behavior? I fear there's some ancient bug in the code, which has been covered since now by somethink in VS6...

Thanks anyone for support, anyway.

1

There are 1 answers

1
Marco Veglio On BEST ANSWER

After some futher investigation, we found it was a problem with data structure alignment. In VS options the Struct Member Alignment was set to 4 bytes, while a #pragma pack 2 was present in one of the source files.

Strange enough, everything worked under VS6, the porting to VS2012 made this issue come out.