-
April 20th, 2004, 01:49 PM
#1
ASSERT vs VERIFY
What is the difference between VERIFY and ASSERT? Which should I use, and why not the other?
Mike B
-
April 20th, 2004, 02:06 PM
#2
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
-
April 20th, 2004, 03:37 PM
#3
How about neither
ENFORCE
ASSERT
If you don't want to be tied to MFC.
p.s. I sometimes use the MFC versions in MFC programs.
Just passing on alternatives
Wakeup in the morning and kick the day in the teeth!! Or something like that.
"i don't want to write leak free code or most efficient code, like others traditional (so called expert) coders do."
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|