I have the following code:
#pragma optimize("", off)
DG704API_API bool DIG704IsUSBEx(IN BYTE rack)
{
volatile bool retVal(true);
try
{
// Validate rack
if ((rack < 1) || (rack > gpData.num70X))
{
OutputDebugMsg(DBG_ERROR_LEVEL, "DIG704IsUSBEx: rack out of hardware range");
throw (ERROR_INVALID_RACK); // Throw rack error
}
// The DIG-704s should always be first in the list
if (rack <= ((BYTE)gpData.num704))
retVal = false; // We are a DIG-704 so return false
if (retVal)
OutputDebugMsg(DBG_INFO_LEVEL, "Rack %d is a DIG-705", rack);
else
OutputDebugMsg(DBG_INFO_LEVEL, "Rack %d is a DIG-704", rack);
}
catch(int error)
{
retVal = false;
}
return (retVal);
}
#pragma optimize("", on)
In Debug Mode if the card is a DIG-704 it returns false. In Release Mode if the card is a DIG-704 it returns true.
In the software/hardware that I am using I have one DIG-704. rack = 1 gpData.num704 = 1
It should return false, but when I look at the value returned it is true and when I step through the code it skips over the line retVal = false; There is no exception being thrown.
gpData is a data structure that is effectively global to the entire program. num704 is declared as an int.
My first guess was that the code was being optimized out so I tried to turn off optimizations, but adding the #pragma and volatile had no affect.
I'm at a loss as to what to try next.
The problem was not with the function. The problem was with the Pascal code that was calling the function. For a function declaration I had:
Function DIG704IsUSBEx(rack: BYTE): Bool; cdecl; External 'DG704API.dll';
It needed to be:
Function DIG704IsUSBEx(rack: BYTE): Boolean; cdecl; External 'DG704API.dll';
I guess that I didn't include enough information for anybody to answer the question. I tried my best and I didn't think Pascal was the problem because when I stepped through the function in Release mode I saw it just skip over the code.
Thank you to everybody who tried to help.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.