Possible Duplicate:
Can I redefine a C++ macro then define it back?
I have an application that calls a function from a third party SDK lots of times along the app lifetime. This third party function checks for some errors with its _3RDPARTY_ASSERT (which is a wrapper around _ASSERT).
My problem is that in one of these calls, I sometimes expect an error (and handle it afterwards). I would like to disable the assert in this case, as it's quite annoying while debugging, but keep it in all the other cases.
I have tried to handle it with pragma push_macro/pop_macro but I haven't found a way. Is this possible?
I have the source of 3rdParty.cpp but would prefer not to touch it.
This would be a simplified version of the code:
mine.cpp:
#include "3rdparty.h"
HRESULT MyMethod(...)
{
HRESULT hr;
hr = _3rdParty(...);
if (SUCCEEDED(hr))
hr = _3rdParty(...);
if (SUCCEEDED(hr))
hr = _3rdParty(...);
...
if (SUCCEEDED(hr))
hr = _3rdParty(...); // This call shouldn't throw the assertion, as I expect it to fail sometimes!
if (FAILED(hr))
doSomething();
else
doSomethingElse();
...
if (SUCCEEDED(hr))
hr = _3rdParty(...);
return hr;
}
3rdParty.cpp:
...
#define _3RDPARTY_ASSERT (_ASSERT)
...
HRESULT _3rdParty(...)
{
HRESULT hr;
hr = SomeFunction();
_3RDPARTY_ASSERT(SUCCEEDED(hr));
return hr;
}