|
1 | 1 | ---
|
2 | 2 | title: "_Noreturn keyword and noreturn macro (C11)"
|
3 | 3 | description: "Describes the `_Noreturn` keyword and `noreturn` macro."
|
4 |
| -ms.date: 10/16/2020 |
| 4 | +ms.date: 10/19/2020 |
5 | 5 | f1_keywords: ["_Noreturn_c", "noreturn"]
|
6 | 6 | helpviewer_keywords: ["keywords [C]"]
|
7 | 7 | ---
|
8 | 8 |
|
9 | 9 | # `_Noreturn` keyword and `noreturn` macro (C11)
|
10 | 10 |
|
11 |
| -The `_Noreturn` keyword was introduced in C11. It tells the compiler that the function it's applied to doesn't return. The compiler knows that the code following a call to a `_Noreturn` function is unreachable. |
| 11 | +The `_Noreturn` keyword was introduced in C11. It tells the compiler that the function it's applied to doesn't return to the caller. The compiler knows that the code following a call to a `_Noreturn` function is unreachable. An example of a function that doesn't return is [abort](../c-runtime-library/reference/abort.md). If there's a possibility for control flow to return to the caller, the function must not have the `_Noreturn` attribute. |
12 | 12 |
|
13 |
| -A convenience macro, `noreturn`, provided in <stdnoreturn.h>, maps to the `_Noreturn` keyword. |
| 13 | +The keyword is typically used through the convenience macro, `noreturn`, provided in <stdnoreturn.h>, which maps to the `_Noreturn` keyword. |
14 | 14 |
|
15 | 15 | The primary benefits for using `_Noreturn` (or the equivalent `noreturn`) are making the intention of the function clear in the code for future readers, and detecting unintentionally unreachable code.
|
16 | 16 |
|
| 17 | +A function marked `noreturn` shouldn't include a return type because it doesn't return a value to the caller. It should be `void`. |
| 18 | + |
17 | 19 | ## Example using `noreturn` macro and `_Noreturn `keyword
|
18 | 20 |
|
19 | 21 | The following example demonstrates the `_Noreturn` keyword and the equivalent `noreturn` macro.
|
@@ -61,5 +63,6 @@ int main(void)
|
61 | 63 | ## See also
|
62 | 64 |
|
63 | 65 | [/std (Specify language standard version)](../build/reference/std-specify-language-standard-version.md)\
|
64 |
| -[/W4 (Specify warning level)](../build/reference/compiler-option-warning-level.md) |
65 |
| -[C4702 warning](../error-messages\compiler-warnings\compiler-warning-level-4-c4702.md) |
| 66 | +[/W4 (Specify warning level)](../build/reference/compiler-option-warning-level.md)\ |
| 67 | +[C4702 warning](../error-messages\compiler-warnings\compiler-warning-level-4-c4702.md)\ |
| 68 | +[__declspec(noreturn)](../cpp/noreturn.md) |
0 commit comments