I have the following code here. My problem is that when the switch...case block hits nIDEvent == 1, SlavePos structure (which is an array of 6 floating point numbers) is modified by (0, +/- delta, 0, 0, 0, 0). But when the debugger hits the line "break;", SlavePos's values return to the original values before exiting the function. Does anyone know what type of scope problem that I'm running into in this case? Thanks in advance.

switch(nIDEvent)
{
case 1:
// This is used to attempt to move the needle
if (lpressed)
theNeedle->SlavePos[1] -= delta;
if (rpressed)
theNeedle->SlavePos[1] += delta;
break;
case 2:
// some other handling code that is not relevant to the problem
break;
}
CView::OnTimer(nIDEvent);
}

04-14-2009

phantomotap

Are you sure it is being modified?
Alternatively... are you sure it isn't being modified twice?

Soma

04-14-2009

matsp

To me, scope problem means that you are hiding a variable or using the address of a variable that is out of scope, neither of which this appears to be from the posted code.

What other code do you have that changes this variable?

--
Mats

04-14-2009

stanlvw

Only the constructor makes changes to the array, and then it's never called again. I have a hard time finding what else is modifying the variable. I checked that the variable is modified within the if statements when appropriate, only to find out that they have been modified back again when the program hits "break;" in the debugger.

04-14-2009

stanlvw

I think I have found out a potential culprit. delta is a float type. SlavePos is actually a FLOAT type. I'm not sure why they would make a difference, since FLOAT is a Windows typedef of float, but according to my observations, it did.

04-14-2009

brewbuck

Are you by chance compiling with optimization?

04-14-2009

stanlvw

From what I see in the optimization settings in the Visual Studio project, no.