Skip to content

Commit 7757a64

Browse files
authored
Merge pull request #6119 from TylerMSFT/warningdirective
new article for #warning
2 parents 78bc7a3 + ed81a24 commit 7757a64

File tree

4 files changed

+42
-7
lines changed

4 files changed

+42
-7
lines changed

docs/preprocessor/hash-error-directive-c-cpp.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,10 @@ title: "#error directive (C/C++)"
44
ms.date: "08/29/2019"
55
f1_keywords: ["#error"]
66
helpviewer_keywords: ["#error directive", "preprocessor, directives", "error directive (#error directive)"]
7-
ms.assetid: d550a802-ff19-4347-9597-688935d23b2b
87
---
98
# #error directive (C/C++)
109

11-
The **#error** directive emits a user-specified error message at compile time, and then terminates the compilation.
10+
The `#error` directive emits a user-specified error message at compile time. Then it terminates the compilation.
1211

1312
## Syntax
1413

@@ -26,4 +25,5 @@ The error message that this directive emits includes the *token-string* paramete
2625

2726
## See also
2827

29-
[Preprocessor directives](../preprocessor/preprocessor-directives.md)
28+
[Preprocessor directives](../preprocessor/preprocessor-directives.md)\
29+
[#warning directive](../preprocessor/hash-warning-directive-c-cpp.md)
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
---
2+
description: "Learn more about: #warning directive (C/C++)"
3+
title: "#warning directive (C/C++)"
4+
ms.date: 10/15/2025
5+
f1_keywords: ["#warning"]
6+
helpviewer_keywords: ["#warning directive", "preprocessor, directives", "warning directive (#warning directive)"]
7+
---
8+
# #warning directive (C/C++)
9+
10+
The **#warning** directive emits a user-specified warning message at compile time. It doesn't stop compilation. This directive is available starting in C23 and C++23.
11+
12+
## Syntax
13+
14+
> **#warning** *token-string*
15+
16+
## Remarks
17+
18+
The warning message is the *token-string* parameter. The *token-string* parameter isn't subject to macro expansion and can be optionally enclosed in quotes.
19+
20+
Use this directive to inform the developer of a nonfatal issue or to communicate other important information during compilation.
21+
22+
The following example shows how to use the **#warning** directive:
23+
24+
```cpp
25+
#if defined(_LEGACY_FEATURE_FLAG)
26+
#warning "_LEGACY_FEATURE is deprecated and should not be used."
27+
#endif
28+
```
29+
30+
## See also
31+
32+
[Preprocessor directives](../preprocessor/preprocessor-directives.md)\
33+
[#error directive](../preprocessor/hash-error-directive-c-cpp.md)

docs/preprocessor/preprocessor-directives.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
---
22
description: "Learn more about: Preprocessor directives"
33
title: "Preprocessor directives"
4-
ms.date: "08/29/2019"
4+
ms.date: 10/15/2025
55
helpviewer_keywords: ["directives, preprocessor", "preprocessor, directives"]
6-
ms.assetid: e0fc4564-b6cf-4a36-bf51-6ccd7abd0a94
76
---
87
# Preprocessor directives
98

10-
Preprocessor directives, such as `#define` and `#ifdef`, are typically used to make source programs easy to change and easy to compile in different execution environments. Directives in the source file tell the preprocessor to take specific actions. For example, the preprocessor can replace tokens in the text, insert the contents of other files into the source file, or suppress compilation of part of the file by removing sections of text. Preprocessor lines are recognized and carried out before macro expansion. Therefore, if a macro expands into something that looks like a preprocessor command, it isn't recognized by the preprocessor.
9+
Preprocessor directives, such as `#define` and `#ifdef`, are used to make source programs easy to change and compile in different execution environments. Directives in the source file tell the preprocessor to take specific actions. For example, the preprocessor can replace tokens in the text, insert the contents of other files into the source file, or suppress compilation of part of the file by removing sections of text. Preprocessor directives are processed before macro expansion. Therefore, if a macro expands into something that looks like a preprocessor command, it isn't recognized by the preprocessor.
1110

1211
Preprocessor statements use the same character set as source file statements, with the exception that escape sequences aren't supported. The character set used in preprocessor statements is the same as the execution character set. The preprocessor also recognizes negative character values.
1312

@@ -29,7 +28,8 @@ The preprocessor recognizes the following directives:
2928
:::column span="":::
3029
[`#import`](../preprocessor/hash-import-directive-cpp.md)\
3130
[`#include`](../preprocessor/hash-include-directive-c-cpp.md)\
32-
[`#line`](../preprocessor/hash-line-directive-c-cpp.md)
31+
[`#line`](../preprocessor/hash-line-directive-c-cpp.md)\
32+
[`#warning`](../preprocessor/hash-warning-directive-c-cpp.md)
3333
:::column-end:::
3434
:::column span="":::
3535
[`#pragma`](../preprocessor/pragma-directives-and-the-pragma-keyword.md)\

docs/preprocessor/toc.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ items:
9292
href: ../preprocessor/hash-undef-directive-c-cpp.md
9393
- name: "#using directive (C++/CLI)"
9494
href: ../preprocessor/hash-using-directive-cpp.md
95+
- name: "#warning directive (C/C++)"
96+
href: ../preprocessor/hash-warning-directive-c-cpp.md
9597
- name: Preprocessor operators
9698
expanded: false
9799
items:

0 commit comments

Comments
 (0)