I have a VC++ application written using Visual Studio 2008. For debug purposes, timeout values compile differently depending on the type of build (Debug or Release). The code sample below is typical of how I am trying to do this.
#ifdef _DEBUG
if ( (dwObjectWaitState = ::WaitForSingleObject( m_hValidMsgRxdEvent, INFINITE )) != WAIT_OBJECT_0 )
#else
if ( (dwObjectWaitState = ::WaitForSingleObject( m_hValidMsgRxdEvent, BAS_THREE_SEC_TIMEOUT )) != WAIT_OBJECT_0 )
#endif
{
/* ... */
}
The Debug configuration has _DEBUG defined in the Preprocessor Definitions. The Release configuration does not have it. For each respective configuration, the expected lined is grayed out (presumably to indicate that the other line will be compiled in).
However, at run-time, the Release build timeouts remain INFINITE. When I try to set a breakpoint on both if statements and try to run the Release code, the breakpoint on the first if statement remains, whereas the other breakpoint gets moved down to the first line inside the brackets.
What gives? How do I make this compile option work? Should I be using something else?
Something like this instead perhaps?
Edit: Debug builds in VS should have _DEBUG defined and release builds should have NDEBUG defined. Check your project pre-processor directives to make sure this is what you have.