Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

What the heck is ASSERT() and VERIFY()

Status
Not open for further replies.

sirbeatsalot

Programmer
Dec 7, 2001
11
US
ASSERT (nIndex != -1);

What does this do? is it for debugging? its not used to return a value. It doesn't change anything if i comment it out. And VERIFY() as well?? same confusion with that one.
 
These are preprocessor macros that are used to assert or verify that a certain expected condition is true. If the condition fails, the assertion displays an error message and program execution stops.

Of course, the condition being checked should be something that should never be false at that point in the program. It is only used like a sanity check.

Therefore, don't use ASSERT for conditions which may be either true or false. Instead, use the if statement to check for true, false, null, not equal, etc.
 
The book, "Writing Solid Code" by Steve Maguire, is very good and highly encourages the use of assertions in your code. As the title suggests, it offers many other suggestions for avoiding bugs. Check it out!
 
The ASSERT() and ASSERT_VALID() macros are part of CObject, so you can't use them in a class not derived from CObject. ASSERT_VALID() verifies a pointer to a class derived from CObject. These are only necessary for debugging, so when ur project is complete you can turn them off by selecting the Build...Set Active Configuration menu and selecting "release build".

HTH.

~Mike
Any man willing to sacrifice liberty for security deserves neither liberty nor security.

-Ben Franklin
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top