You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/c-runtime-library/reference/assert-macro-assert-wassert.md
+10-10Lines changed: 10 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -50,37 +50,37 @@ The line number in the source file of the failed assertion.
50
50
51
51
The `assert` macro is typically used to identify logic errors during program development. Use it to stop program execution when unexpected conditions occur by implementing the *expression* argument to evaluate to **`false`** only when the program is operating incorrectly. Assertion checks can be turned off at compile time by defining the macro **NDEBUG**. You can turn off the `assert` macro without modifying your source files by using a **/DNDEBUG** command-line option. You can turn off the `assert` macro in your source code by using a `#define NDEBUG` directive before \<assert.h> is included.
52
52
53
-
The `assert` macro prints a diagnostic message when *expression* evaluates to **`false`** (0) and calls [`abort`](abort.md) to terminate program execution. No action is taken if *expression* is **`true`** (nonzero). The diagnostic message includes the failed expression, the name of the source file and line number where the assertion failed.
53
+
The `assert` macro prints a diagnostic message when *expression* evaluates to **`false`** (0) and calls [`abort`](abort.md) to stop program execution. No action is taken if *expression* is **`true`** (nonzero). The diagnostic message includes the failed expression, the name of the source file and line number where the assertion failed.
54
54
55
-
The diagnostic message is printed in wide (`wchar_t`) characters. Thus, it will work as expected even if there are Unicode characters in the expression.
55
+
The diagnostic message is printed in wide (`wchar_t`) characters. Therefore, it will work as expected even if there are Unicode characters in the expression.
56
56
57
-
The destination of the diagnostic message depends on the type of application that called the routine. Console applications receive the message through **stderr**. In a Windows-based application, `assert` calls the Windows [MessageBox](/windows/win32/api/winuser/nf-winuser-messagebox) function to create a message box to display the message with three buttons: **Abort**, **Retry**, and **Ignore**. If the user clicks **Abort**, the program aborts immediately. If the user clicks **Retry**, the debugger is called and the user can debug the program if just-in-time (JIT) debugging is enabled. If the user clicks **Ignore**, the program will continue with normal execution. Note that clicking **Ignore** when an error condition exists can result in undefined behavior since preconditions of the calling code were not met.
57
+
The destination of the diagnostic message depends on the type of application that called the routine. Console applications receive the message through **stderr**. In a Windows-based application, `assert` calls the Windows [MessageBox](/windows/win32/api/winuser/nf-winuser-messagebox) function to create a message box to display the message with three buttons: **Abort**, **Retry**, and **Ignore**. If the user clicks **Abort**, the program aborts immediately. If the user clicks **Retry**, the debugger is called and the user can debug the program if just-in-time (JIT) debugging is enabled. If the user clicks **Ignore**, the program will continue with normal execution. Clicking **Ignore** when an error condition exists can result in undefined behavior since preconditions of the calling code weren't met.
58
58
59
59
To override the default output behavior regardless of the app type, call [`_set_error_mode`](set-error-mode.md) to select between the output-to-stderr and display-dialog-box behavior.
60
60
61
-
After `assert` displays its message, it calls [`abort`](abort.md) which displays a dialog box with **Abort**, **Retry**, and **Ignore** buttons. [`abort`](abort.md) exits the program, so neither the **Retry**nor**Ignore** button will resume execution following the `assert` call. If `assert` displayed a dialog box, the [`abort`](abort.md) dialog box is not shown. The only time the [`abort`](abort.md) dialog box is shown is when `assert` sends its output to stderr.
61
+
After `assert` displays its message, it calls [`abort`](abort.md), which displays a dialog box with **Abort**, **Retry**, and **Ignore** buttons. [`abort`](abort.md) exits the program, so the **Retry**and**Ignore** button won't resume program execution following the `assert` call. If `assert` displayed a dialog box, the [`abort`](abort.md) dialog box isn't shown. The only time the [`abort`](abort.md) dialog box is shown is when `assert` sends its output to stderr.
62
62
63
-
This means that a dialog box is always displayed following an `assert` call in debug mode. The behavior of each button is captured in the below table.
63
+
As a consequence of the above behavior, a dialog box is always displayed following an `assert` call in debug mode. The behavior of each button is captured in the below table.
64
64
65
65
|Error mode|Output to stderr (Console/_OUT_TO_STDERR)|Display Dialog Box (Windows/_OUT_TO_MSGBOX)|
66
66
|----------|----------------|------------------|
67
67
|Abort|Exit immediately with exit code 3|Exit immediately with exit code 3|
68
68
|Retry|Break into debugger during `abort`|Break into debugger during `assert`|
69
-
|Ignore|Finish exiting via `abort`|Continue program as though the assert did not fire (may result in undefined behavior since preconditions of the calling code were not met)|
69
+
|Ignore|Finish exiting via `abort`|Continue program as though the assert didn't fire (may result in undefined behavior since preconditions of the calling code weren't met)|
70
70
71
71
For more information about CRT debugging, see [CRT Debugging Techniques](/visualstudio/debugger/crt-debugging-techniques).
72
72
73
-
The `_assert` and `_wassert` functions are internal CRT functions. They help minimize the code required in your object files to support assertions. We do not recommend that you call these functions directly.
73
+
The `_assert` and `_wassert` functions are internal CRT functions. They help minimize the code required in your object files to support assertions. We don't recommend that you call these functions directly.
74
74
75
-
The `assert` macro is enabled in both the release and debug versions of the C run-time libraries when **NDEBUG**is not defined. When **NDEBUG** is defined, the macro is available but does not evaluate its argument and has no effect. When it is enabled, the `assert` macro calls `_wassert` for its implementation. Other assertion macros, [_ASSERT](assert-asserte-assert-expr-macros.md), [_ASSERTE](assert-asserte-assert-expr-macros.md) and [_ASSERT_EXPR](assert-asserte-assert-expr-macros.md), are also available, but they only evaluate the expressions passed to them when the [_DEBUG](../../c-runtime-library/debug.md) macro has been defined and when they are in code linked with the debug version of the C run-time libraries.
75
+
The `assert` macro is enabled in both the release and debug versions of the C run-time libraries when **NDEBUG**isn't defined. When **NDEBUG** is defined, the macro is available but doesn't evaluate its argument and has no effect. When it's enabled, the `assert` macro calls `_wassert` for its implementation. Other assertion macros, [_ASSERT](assert-asserte-assert-expr-macros.md), [_ASSERTE](assert-asserte-assert-expr-macros.md) and [_ASSERT_EXPR](assert-asserte-assert-expr-macros.md), are also available, but they only evaluate the expressions passed to them when the [_DEBUG](../../c-runtime-library/debug.md) macro has been defined and when they are in code linked with the debug version of the C run-time libraries.
76
76
77
77
## Requirements
78
78
79
79
|Routine|Required header|
80
80
|-------------|---------------------|
81
81
|`assert`, `_wassert`|\<assert.h>|
82
82
83
-
The signature of the `_assert` function is not available in a header file. The signature of the `_wassert` function is only available when the **NDEBUG** macro is not defined.
83
+
The signature of the `_assert` function isn't available in a header file. The signature of the `_wassert` function is only available when the **NDEBUG** macro isn't defined.
84
84
85
85
## Example
86
86
@@ -125,7 +125,7 @@ Analyzing string '(null)'
125
125
Assertion failed: string != NULL, file crt_assert.c, line 25
126
126
```
127
127
128
-
After the assertion failure, depending on the version of the operating system and run-time library, you may see a message box that contains something like the following:
128
+
After the assertion failure, depending on the version of the operating system and run-time library, you may see a message box that contains something similar to:
129
129
130
130
```Output
131
131
A problem caused the program to stop working correctly. Windows will close the program and notify you if a solution is available.
0 commit comments