What is the difference between VERIFY and ASSERT? Which should I use, and why not the other?
Mike B
Printable View
What is the difference between VERIFY and ASSERT? Which should I use, and why not the other?
Mike B
ASSERT(blah blah) is computed only in debug builds. So is not the case with VERIFY(blah blah). It is computed in both debug and release.
Anyways, in release builds there will be no popup if the condition blah blah is false.
When to use and when not to use:
If you are using just checking both are good enough. For e.g.
ASSERT(NULL != pPointer);//in release build does nothing , in debug build will popup an box if the condition fails.
VERIFY(NULL != pPointer);//in release build does nothing , in debug build will popup an box if the condition fails.
However, if the blah blah turns out to be some computation and the result of that has to be checked, ASSERT is not good, since in release builds the whole statement is just not compiled.
For e.g.
ASSERT(pPointer = pPassedPointer)
Here note that , first assignment happens to pPointer and then the result is compared if it is non-zero or not.
For debug builds this will be ok, but for release, the pPointer = pPassedPointer is not compiled at all. So, firther down in your code if you have something relying on pPointer, you see that it is not valid, because the statement withing ASSERT did not get executed, because it was not even a statement during compile time.
This is a classic case of putting in VERIFY