CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Hybrid View

  1. #1
    Join Date
    Feb 2001
    Posts
    2,455

    ASSERT vs VERIFY

    What is the difference between VERIFY and ASSERT? Which should I use, and why not the other?

    Mike B

  2. #2
    Join Date
    Feb 2000
    Location
    San Diego, CA
    Posts
    10,354
    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

  3. #3
    Join Date
    Nov 2002
    Location
    Los Angeles, California
    Posts
    3,863
    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
  •  





Click Here to Expand Forum to Full Width

Featured