PRB: Misuse of ASSERT Causes Problems for MFC Apps (115086)
The information in this article applies to:
- The Microsoft Foundation Classes (MFC), when used with:
- Microsoft C/C++ for MS-DOS 7.0
- Microsoft Visual C++ for Windows, 16-bit edition 1.0
- Microsoft Visual C++ for Windows, 16-bit edition 1.5
- Microsoft Visual C++ for Windows, 16-bit edition 1.51
- Microsoft Visual C++ for Windows, 16-bit edition 1.52
- Microsoft Visual C++, 32-bit Editions 1.0
- Microsoft Visual C++, 32-bit Editions 2.0
- Microsoft Visual C++, 32-bit Editions 2.1
- Microsoft Visual C++, 32-bit Editions 4.0
This article was previously published under Q115086
The information in this article is included in the documentation starting
with Visual C++ 5.0. Look there for future revisions.
SYMPTOMS
When you run the debug version of your MFC application, there are no
problems. However, the release version of the same application crashes,
returns incorrect results, and/or exhibits some other abnormal behavior.
CAUSE
This problem can be caused when you place important code in an ASSERT
statement to verify that it performs correctly. Because ASSERT statements
are commented out in a release build of an MFC program, the code does not
run in a release build.
RESOLUTION
If you are using ASSERT to confirm that a function call succeeded, consider
using VERIFY instead. The VERIFY macro evaluates its own arguments in both
debug and release builds of the application.
Another preferred technique is to assign the function's return value to a
temporary variable and then test the variable in an ASSERT statement.
Both of these techniques are demonstrated below in the "MORE INFORMATION"
section of this article.
Modification Type: | Major | Last Reviewed: | 12/2/2003 |
---|
Keywords: | kbprb KB115086 |
---|
|