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
@@ -82,7 +83,7 @@ The `__MSVC_RUNTIME_CHECKS` preprocessor directive will be defined when you use
82
83
83
84
1. Open the project's **Property Pages** dialog box. For details, see [Set C++ compiler and build properties in Visual Studio](../working-with-project-properties.md).
84
85
85
-
1. Select the **Configuration Properties** > **C/C++****Code Generation** property page.
86
+
1. Select the **Configuration Properties** > **C/C++**>**Code Generation** property page.
86
87
87
88
1. Modify one or both of the following properties: **Basic Runtime Checks** or **Smaller Type Check**.
Adds recommended Security Development Lifecycle (SDL) checks. These checks include extra security-relevant warnings as errors, and additional secure code-generation features.
10
+
Enables recommended Security Development Lifecycle (SDL) checks. These checks change security-relevant warnings into errors, and set additional secure code-generation features.
10
11
11
12
## Syntax
12
13
@@ -16,53 +17,51 @@ Adds recommended Security Development Lifecycle (SDL) checks. These checks inclu
16
17
17
18
**/sdl** enables a superset of the baseline security checks provided by [`/GS`](gs-buffer-security-check.md) and overrides **`/GS-`**. By default, **`/sdl`** is off. **`/sdl-`** disables the additional security checks.
18
19
19
-
## Compile-time Checks
20
+
###Compile-time Checks
20
21
21
22
**`/sdl`** enables these warnings as errors:
22
23
23
-
|Warning enabled by /sdl|Equivalent command-line switch|Description|
|[C4146](../../error-messages/compiler-warnings/compiler-warning-level-2-c4146.md)|/we4146|A unary minus operator was applied to an unsigned type, resulting in an unsigned result.|
26
-
|[C4308](../../error-messages/compiler-warnings/compiler-warning-level-2-c4308.md)|/we4308|A negative integral constant converted to unsigned type, resulting in a possibly meaningless result.|
27
-
|[C4532](../../error-messages/compiler-warnings/compiler-warning-level-1-c4532.md)|/we4532|Use of `continue`, `break` or `goto` keywords in a `__finally`/`finally` block has undefined behavior during abnormal termination.|
28
-
|[C4533](../../error-messages/compiler-warnings/compiler-warning-level-1-c4533.md)|/we4533|Code initializing a variable will not be executed.|
29
-
|[C4700](../../error-messages/compiler-warnings/compiler-warning-level-1-and-level-4-c4700.md)|/we4700|Use of an uninitialized local variable.|
30
-
|[C4703](../../error-messages/compiler-warnings/compiler-warning-level-4-c4703.md)|/we4703|Use of a potentially uninitialized local pointer variable.|
31
-
|[C4789](../../error-messages/compiler-warnings/compiler-warning-level-1-c4789.md)|/we4789|Buffer overrun when specific C run-time (CRT) functions are used.|
32
-
|[C4995](../../error-messages/compiler-warnings/compiler-warning-level-3-c4995.md)|/we4995|Use of a function marked with pragma [`deprecated`](../../preprocessor/deprecated-c-cpp.md).|
33
-
|[C4996](../../error-messages/compiler-warnings/compiler-warning-level-3-c4996.md)|/we4996|Use of a function marked as [`deprecated`](../../cpp/deprecated-cpp.md).|
24
+
|Warning enabled by /sdl|Equivalent command-line switch|Description|
25
+
|--|--|--|
26
+
|[C4146](../../error-messages/compiler-warnings/compiler-warning-level-2-c4146.md)|/we4146|A unary minus operator was applied to an unsigned type, resulting in an unsigned result.|
27
+
|[C4308](../../error-messages/compiler-warnings/compiler-warning-level-2-c4308.md)|/we4308|A negative integral constant converted to unsigned type, resulting in a possibly meaningless result.|
28
+
|[C4532](../../error-messages/compiler-warnings/compiler-warning-level-1-c4532.md)|/we4532|Use of `continue`, `break`, or `goto` keywords in a `__finally`/`finally` block has undefined behavior during abnormal termination.|
29
+
|[C4533](../../error-messages/compiler-warnings/compiler-warning-level-1-c4533.md)|/we4533|Code initializing a variable will not be executed.|
30
+
|[C4700](../../error-messages/compiler-warnings/compiler-warning-level-1-and-level-4-c4700.md)|/we4700|Use of an uninitialized local variable.|
31
+
|[C4703](../../error-messages/compiler-warnings/compiler-warning-level-4-c4703.md)|/we4703|Use of a potentially uninitialized local pointer variable.|
32
+
|[C4789](../../error-messages/compiler-warnings/compiler-warning-level-1-c4789.md)|/we4789|Buffer overrun when specific C run-time (CRT) functions are used.|
33
+
|[C4995](../../error-messages/compiler-warnings/compiler-warning-level-3-c4995.md)|/we4995|Use of a function marked with pragma [`deprecated`](../../preprocessor/deprecated-c-cpp.md).|
34
+
|[C4996](../../error-messages/compiler-warnings/compiler-warning-level-3-c4996.md)|/we4996|Use of a function marked as [`deprecated`](../../cpp/deprecated-cpp.md).|
34
35
35
-
## Runtime checks
36
+
###Runtime checks
36
37
37
-
When **`/sdl`** is enabled, the compiler generates code to perform these checks at run time:
38
+
When **`/sdl`** is enabled, the compiler generates code that does these checks at run time:
38
39
39
40
- Enables the strict mode of **`/GS`** run-time buffer overrun detection, equivalent to compiling with `#pragma strict_gs_check(push, on)`.
40
41
41
-
-Performs limited pointer sanitization. In expressions that do not involve dereferences and in types that have no user-defined destructor, pointer references are set to a non-valid address after a call to **`delete`**. This helps to prevent the reuse of stale pointer references.
42
+
-Does limited pointer sanitization. In expressions that don't involve dereferences and in types that have no user-defined destructor, pointer references are set to a non-valid address after a call to **`delete`**. This sanitization helps to prevent the reuse of stale pointer references.
42
43
43
-
-Performs class member pointer initialization. Automatically initializes class members of pointer type to **`nullptr`** on object instantiation (before the constructor runs). This helps prevent the use of uninitialized pointers that the constructor does not explicitly initialize. The compiler-generated member pointer initialization is called as long as:
44
+
-Initializes class member pointers. Automatically initializes class members of pointer type to **`nullptr`** on object instantiation (before the constructor runs). It helps prevent the use of uninitialized pointers that the constructor doesn't explicitly initialize. The compiler-generated member pointer initialization is called as long as:
44
45
45
-
- The object is not allocated using a custom (user defined) `operator new`
46
+
- The object isn't allocated using a custom (user defined) `operator new`
46
47
47
-
- The object is not allocated as part of an array (for example `new A[x]`)
48
+
- The object isn't allocated as part of an array (for example `new A[x]`)
48
49
49
-
- The class is not managed or imported
50
+
- The class isn't managed or imported
50
51
51
52
- The class has a user-defined default constructor.
52
53
53
54
To be initialized by the compiler-generated class initialization function, a member must be a pointer, and not a property or constant.
54
55
55
-
## Remarks
56
-
57
-
For more information, see [Warnings, /sdl, and improving uninitialized variable detection](https://cloudblogs.microsoft.com/microsoftsecure/2012/06/06/warnings-sdl-and-improving-uninitialized-variable-detection/).
56
+
For more information, see [Warnings, /sdl, and improving uninitialized variable detection](https://www.microsoft.com/security/blog/2012/06/06/warnings-sdl-and-improving-uninitialized-variable-detection/).
58
57
59
-
####To set this compiler option in the Visual Studio development environment
58
+
### To set this compiler option in the Visual Studio development environment
60
59
61
60
1. Open the project's **Property Pages** dialog box. For details, see [Set C++ compiler and build properties in Visual Studio](../working-with-project-properties.md).
62
61
63
-
1. Select the **C/C++**folder.
62
+
1. Select the **Configuration Properties** > **C/C++**> **General** property page.
64
63
65
-
1.On the **General**page, select the option from the **SDL checks** drop-down list.
64
+
1.Set the **SDL checks**property by using the property drop-down control. Choose **OK** or **Apply** to save your changes.
Copy file name to clipboardExpand all lines: docs/c-language/c-enumeration-declarations.md
+39-40Lines changed: 39 additions & 40 deletions
Original file line number
Diff line number
Diff line change
@@ -1,66 +1,65 @@
1
1
---
2
-
title: "C Enumeration Declarations"
3
-
ms.date: "11/04/2016"
2
+
title: "C enumeration declarations"
3
+
description: "Enumeration declarations in the C programming language."
4
+
ms.date: 10/02/2020
4
5
helpviewer_keywords: ["declarations, enumerations", "define directive (#define), alternative to", "enumerators, declaring", "#define directive, alternative to", "named constants, enumeration declarations", "declaring enumerations"]
5
6
ms.assetid: bd18f673-4dda-4bc1-92fd-d1ce10074910
6
7
---
7
-
# C Enumeration Declarations
8
+
# C enumeration declarations
8
9
9
-
An enumeration consists of a set of named integer constants. An enumeration type declaration gives the name of the (optional) enumeration tag and defines the set of named integer identifiers (called the "enumeration set," "enumerator constants," "enumerators," or "members"). A variable with enumeration type stores one of the values of the enumeration set defined by that type.
10
+
An enumeration consists of a set of named integer constants. An enumeration type declaration gives the name of the (optional) enumeration tag. And, it defines the set of named integer identifiers (called the *enumeration set*, *enumerator constants*, *enumerators*, or *members*). A variable of the enumeration type stores one of the values of the enumeration set defined by that type.
10
11
11
12
Variables of **`enum`** type can be used in indexing expressions and as operands of all arithmetic and relational operators. Enumerations provide an alternative to the `#define` preprocessor directive with the advantages that the values can be generated for you and obey normal scoping rules.
12
13
13
-
In ANSI C, the expressions that define the value of an enumerator constant always have **`int`** type; thus, the storage associated with an enumeration variable is the storage required for a single **`int`** value. An enumeration constant or a value of enumerated type can be used anywhere the C language permits an integer expression.
14
+
In ANSI C, the expressions that define the value of an enumerator constant always have **`int`** type. That means the storage associated with an enumeration variable is the storage required for a single **`int`** value. An enumeration constant or a value of enumerated type can be used anywhere the C language permits an integer expression.
The optional *identifier* names the enumeration type defined by *enumerator-list*. This identifier is often called the "tag" of the enumeration specified by the list. A type specifier of the form
The optional *`identifier`* names the enumeration type defined by *`enumerator-list`*. This identifier is often called the "tag" of the enumeration specified by the list. A type specifier declares `identifier` to be the tag of the enumeration specified by the *`enumerator-list`* nonterminal, as seen here:
34
+
35
+
```C
24
36
enum identifier
25
37
{
26
-
enumerator-list
38
+
// enumerator-list
27
39
}
28
40
```
29
41
30
-
declares *identifier* to be the tag of the enumeration specified by the *enumerator-list* nonterminal. The *enumerator-list* defines the "enumerator content." The *enumerator-list* is described in detail below.
31
-
32
-
If the declaration of a tag is visible, subsequent declarations that use the tag but omit *enumerator-list* specify the previously declared enumerated type. The tag must refer to a defined enumeration type, and that enumeration type must be in current scope. Since the enumeration type is defined elsewhere, the *enumerator-list* does not appear in this declaration. Declarations of types derived from enumerations and **`typedef`** declarations for enumeration types can use the enumeration tag before the enumeration type is defined.
The *`enumerator-list`* defines the members of the enumeration set.
43
43
44
-
*enumeration-constant*:<br/>
45
-
*identifier*
44
+
If the declaration of a tag is visible, later declarations that use the tag but omit *`enumerator-list`* specify the previously declared enumerated type. The tag must refer to a defined enumeration type, and that enumeration type must be in current scope. Since the enumeration type is defined elsewhere, the *`enumerator-list`* doesn't appear in this declaration. Declarations of types derived from enumerations and **`typedef`** declarations for enumeration types can use the enumeration tag before the enumeration type is defined.
46
45
47
-
Each *enumeration-constant* in an *enumeration-list* names a value of the enumeration set. By default, the first *enumeration-constant* is associated with the value 0. The next *enumeration-constant* in the list is associated with the value of ( *constant-expression* + 1 ), unless you explicitly associate it with another value. The name of an *enumeration-constant* is equivalent to its value.
46
+
Each *`enumeration-constant`* in an *`enumerator-list`* names a value of the enumeration set. By default, the first *`enumeration-constant`* is associated with the value 0. The next *`enumeration-constant`* in the list is associated with the value of ( *`constant-expression`* + 1 ), unless you explicitly associate it with another value. The name of an *`enumeration-constant`* is equivalent to its value.
48
47
49
-
You can use *enumeration-constant = constant-expression* to override the default sequence of values. Thus, if *enumeration-constant = constant-expression* appears in the *enumerator-list*, the *enumeration-constant* is associated with the value given by *constant-expression*. The *constant-expression* must have **`int`** type and can be negative.
48
+
You can use *`enumeration-constant`* = *`constant-expression`* to override the default sequence of values. That is, if *`enumeration-constant`* = *`constant-expression`* appears in the *`enumerator-list`*, the *`enumeration-constant`* is associated with the value given by *`constant-expression`*. The *`constant-expression`* must have **`int`** type and can be negative.
50
49
51
50
The following rules apply to the members of an enumeration set:
52
51
53
-
- An enumeration set can contain duplicate constant values. For example, you could associate the value 0 with two different identifiers, perhaps named `null` and `zero`, in the same set.
52
+
- An enumeration set can contain duplicate constant values. For example, you could associate the value 0 with two different identifiers, for example, members named `null` and `zero`, in the same set.
54
53
55
-
- The identifiers in the enumeration list must be distinct from other identifiers in the same scope with the same visibility, including ordinary variable names and identifiers in other enumeration lists.
54
+
- The identifiers in the enumeration list must be distinct from other identifiers in the same scope with the same visibility. That includes ordinary variable names and identifiers in other enumeration lists.
56
55
57
56
- Enumeration tags obey the normal scoping rules. They must be distinct from other enumeration, structure, and union tags with the same visibility.
58
57
59
58
## Examples
60
59
61
60
These examples illustrate enumeration declarations:
62
61
63
-
```
62
+
```C
64
63
enum DAY /* Defines an enumeration type */
65
64
{
66
65
saturday, /* Names day and declares a */
@@ -77,21 +76,21 @@ The value 0 is associated with `saturday` by default. The identifier `sunday` is
77
76
78
77
In this example, a value from the set `DAY` is assigned to the variable `today`.
79
78
80
-
```
79
+
```C
81
80
enum DAY today = wednesday;
82
81
```
83
82
84
-
Note that the name of the enumeration constant is used to assign the value. Since the `DAY` enumeration type was previously declared, only the enumeration tag `DAY` is necessary.
83
+
The name of the enumeration constant is used to assign the value. Since the `DAY` enumeration type was previously declared, only the enumeration tag `DAY` is necessary.
85
84
86
85
To explicitly assign an integer value to a variable of an enumerated data type, use a type cast:
87
86
88
-
```
87
+
```C
89
88
workday = ( enum DAY ) ( day_value - 1 );
90
89
```
91
90
92
-
This cast is recommended in C but is not required.
91
+
This cast is recommended in C but isn't required.
93
92
94
-
```
93
+
```C
95
94
enum BOOLEAN /* Declares an enumeration data type called BOOLEAN */
96
95
{
97
96
false, /* false = 0, true = 1 */
@@ -103,20 +102,20 @@ enum BOOLEAN end_flag, match_flag; /* Two variables of type BOOLEAN */
An example that uses these variables might look like this:
118
117
119
-
```
118
+
```C
120
119
if ( match_flag == false )
121
120
{
122
121
.
@@ -128,7 +127,7 @@ if ( match_flag == false )
128
127
129
128
Unnamed enumerator data types can also be declared. The name of the data type is omitted, but variables can be declared. The variable `response` is a variable of the type defined:
0 commit comments