Assert vs Verify |
|
Visual C++ has its own variations of the assert and verify macors that are used in debugging. They both both are only written in debug builds of your program, they both query an expression as to whether or not it is true or false, and they both throw an assertion if its expression is false. Seem redundant? Aren't these interchangable? No, they both behave differently when you compile a release version of your program, and not knowing the difference between the two will have drastic results. The big difference between these two is that in the release versin: ASSERT will not written out, and its expression that would have been evaluated will be deleted. VERIFY will not written out, but its expression that would have been evaluated will be left intact. Here is an example that demonstates creating a window (in a window class' constructor) and making sure that it's created properly (don't worry about the create parameters): ASSERT(this->create(CProject::IDD_Dialog, pParent)); this->ShowWindow(SW_NORMAL); or: VERIFY(this->create(CProject::IDD_Dialog, pParent)); this->ShowWindow(SW_NORMAL); If you compile a release version of this, the first example will never be able to create the window because its expression (this->create(CProject::IDD_Dialog, pParent) will be deleted. The second example will work just fine because its expression will be left alone. VERIFY's are used for making sure that already existing code is working properly, and ASSERT's are perfect for Run-Time-Type-Identification that won't be necessary in a release version of your product. |
|
This page is best viewed in 800x600x256. This page was last edited Saturday, July 15, 2000 |