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
**ANSI 3.2.1.1** Whether a "plain" **char** has the same range of values as a **signed char** or an `unsigned char`
8
+
**ANSI 3.2.1.1** Whether a "plain" **char** has the same range of values as a **signed char** or an **unsigned char**
9
9
10
10
All signed character values range from -128 to 127. All unsigned character values range from 0 to 255.
11
11
12
-
The /J compiler option changes the default from **signed** to `unsigned`.
12
+
The [`/J`](../build/reference/j-default-char-type-is-unsigned.md) compiler option changes the default type for **char**from **signed char** to **unsigned char**.
**ANSI 3.2.1.4** The direction of truncation or rounding when a floating-point number is converted to a narrower floating-point number
10
10
11
-
When an underflow occurs, the value of a floating-point variable is rounded down to zero. An overflow may cause a run-time error or it may produce an unpredictable value, depending on the optimizations specified.
11
+
When an underflow occurs, the value of a floating-point variable is rounded to zero. An overflow may cause a run-time error or it may produce an unpredictable value, depending on the optimizations specified.
Copy file name to clipboardExpand all lines: docs/c-language/values.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,7 +11,7 @@ The **float** type contains 32 bits: 1 for the sign, 8 for the exponent, and 23
11
11
12
12
The **double** type contains 64 bits: 1 for the sign, 11 for the exponent, and 52 for the mantissa. Its range is +/- 1.7E308 with at least 15 digits of precision.
13
13
14
-
The **long double** type contains 80 bits: 1 for the sign, 15 for the exponent, and 64 for the mantissa. Its range is +/- 1.2E4932 with at least 19 digits of precision. Note that with the Microsoft C compiler, the representation of type **long double**is identical to type **double**.
14
+
The **long double** type is distinct, but has the same representation as type **double**in the Microsoft C compiler.
The *expression* must be of an integral type or of a class type for which there is an unambiguous conversion to integral type. Integral promotion is performed as described in [Standard Conversions](standard-conversions.md).
24
+
The *expression* must have an integral type, or be a class type that has an unambiguous conversion to integral type. Integral promotion takes place as described in [Standard conversions](standard-conversions.md).
23
25
24
-
The **switch** statement body consists of a series of **case** labels and an optional **default** label. No two constant expressions in **case** statements can evaluate to the same value. The **default** label can appear only once. The labeled statements are not syntactic requirements, but the **switch** statement is meaningless without them. The default statement need not come at the end; it can appear anywhere in the body of the switch statement. A case or default label can only appear inside a switch statement.
26
+
The **switch** statement body consists of a series of **case** labels and an optional **default** label. Collectively, the statements that follow the labels are called *labeled* statements. The labeled statements aren't syntactic requirements, but the **switch** statement is meaningless without them. No two constant expressions in **case** statements may evaluate to the same value. The **default** label may appear only once. The **default** statement is often placed at the end, but it can appear anywhere in the body of the **switch** statement. A **case** or **default** label can only appear inside a **switch** statement.
25
27
26
-
The *constant-expression* in each **case** label is converted to the type of *expression* and compared with *expression* for equality. Control passes to the statement whose **case***constant-expression* matches the value of *expression*. The resulting behavior is shown in the following table.
28
+
The *constant-expression* in each **case** label is converted to the type of *expression*. Then, it's compared with *expression* for equality. Control passes to the statement whose **case***constant-expression* matches the value of *expression*. The resulting behavior is shown in the following table.
27
29
28
-
### Switch Statement Behavior
30
+
### Switch statement behavior
29
31
30
-
|Condition|Action|
31
-
|---------------|------------|
32
-
|Converted value matches that of the promoted controlling expression.|Control is transferred to the statement following that label.|
33
-
|None of the constants match the constants in the **case** labels; a **default** label is present.|Control is transferred to the **default** label.|
34
-
|None of the constants match the constants in the **case** labels; **default** label is not present.|Control is transferred to the statement after the **switch** statement.|
32
+
|Condition|Action|
33
+
|--|--|
34
+
|Converted value matches that of the promoted controlling expression.|Control is transferred to the statement following that label.|
35
+
|None of the constants match the constants in the **case** labels; a **default** label is present.|Control is transferred to the **default** label.|
36
+
|None of the constants match the constants in the **case** labels; no **default** label is present.|Control is transferred to the statement after the **switch** statement.|
35
37
36
-
If a matching expression is found, control is not impeded by subsequent **case** or **default** labels. The [break](../cpp/break-statement-cpp.md) statement is used to stop execution and transfer control to the statement after the **switch** statement. Without a **break** statement, every statement from the matched **case** label to the end of the **switch**, including the **default**, is executed. For example:
38
+
If a matching expression is found, execution can continue through later **case** or **default** labels. The [`break`](../cpp/break-statement-cpp.md) statement is used to stop execution and transfer control to the statement after the **switch** statement. Without a **break** statement, every statement from the matched **case** label to the end of the **switch**, including the **default**, is executed. For example:
37
39
38
40
```cpp
39
41
// switch_statement1.cpp
40
42
#include<stdio.h>
41
43
42
44
intmain() {
43
-
char *buffer = "Any character stream";
44
-
int capa, lettera, nota;
45
+
const char *buffer = "Any character stream";
46
+
int uppercase_A, lowercase_a, other;
45
47
char c;
46
-
capa = lettera = nota = 0;
48
+
uppercase_A = lowercase_a = other = 0;
47
49
48
50
while ( c = *buffer++ ) // Walks buffer until NULL
In the above example, `capa` is incremented if `c` is an uppercase `A`. The **break** statement after `capa++` terminates execution of the **switch** statement body and control passes to the **while** loop. Without the **break** statement, execution would "fall through" to the next labeled statement, so that `lettera` and `nota` would also be incremented. A similar purpose is served by the **break** statement for `case 'a'`. If `c` is a lowercase `a`, `lettera` is incremented and the **break** statement terminates the **switch** statement body. If `c`is not an `a` or `A`, the **default** statement is executed.
69
+
In the above example, `uppercase_A` is incremented if `c` is an uppercase `'A'`. The **break** statement after `uppercase_A++` terminates execution of the **switch** statement body and control passes to the **while** loop. Without the **break** statement, execution would "fall through" to the next labeled statement, so that `lowercase_a` and `other` would also be incremented. A similar purpose is served by the **break** statement for `case 'a'`. If `c` is a lowercase `'a'`, `lowercase_a` is incremented and the **break** statement terminates the **switch** statement body. If `c`isn't an `'a'` or `'A'`, the **default** statement is executed.
68
70
69
-
**Visual Studio 2017 and later:** (available with [/std:c++17](../build/reference/std-specify-language-standard-version.md)) The `[[fallthrough]]` attribute is specified in the C++17 standard. It can be used in a **switch** statement as a hint to the compiler (or to anyone reading the code) that fall-through behavior is intended. The Microsoft C++ compiler currently does not warn on fallthrough behavior, so this attribute has no effect on compiler behavior. Note that the attribute is applied to an empty statement within the labeled statement; in other words the semicolon is necessary.
71
+
**Visual Studio 2017 and later:** (available with [/std:c++17](../build/reference/std-specify-language-standard-version.md)) The `[[fallthrough]]` attribute is specified in the C++17 standard. You can use it in a **switch** statement. It's a hint to the compiler, or anyone who reads the code, that fall-through behavior is intentional. The Microsoft C++ compiler currently doesn't warn on fallthrough behavior, so this attribute has no effect on compiler behavior. In the example, the attribute gets applied to an empty statement within the unterminated labeled statement. In other words, the semicolon is necessary.
70
72
71
73
```cpp
72
74
intmain()
@@ -94,7 +96,7 @@ int main()
94
96
}
95
97
```
96
98
97
-
**Visual Studio 2017 version 15.3 and later** (available with [/std:c++17](../build/reference/std-specify-language-standard-version.md)): A switch statement may introduce and initialize a variable whose scope is limited to the block of the switch statement:
99
+
**Visual Studio 2017 version 15.3 and later** (available with [/std:c++17](../build/reference/std-specify-language-standard-version.md)). A switch statement may have an *initialization* clause. It introduces and initializes a variable whose scope is limited to the block of the switch statement:
98
100
99
101
```cpp
100
102
switch (Gadget gadget(args); auto s = gadget.get_status())
@@ -107,7 +109,7 @@ int main()
107
109
};
108
110
```
109
111
110
-
An inner block of a **switch** statement can contain definitions with initializations as long as they are reachable — that is, not bypassed by all possible execution paths. Names introduced using these declarations have local scope. For example:
112
+
An inner block of a **switch** statement can contain definitions with initializations as long as they're *reachable*, that is, not bypassed by all possible execution paths. Names introduced using these declarations have local scope. For example:
111
113
112
114
```cpp
113
115
// switch_statement2.cpp
@@ -142,16 +144,14 @@ int main(int argc, char *argv[])
142
144
}
143
145
```
144
146
145
-
A **switch** statement can be nested. In such cases,**case** or **default** labels associate with the closest **switch** statement that encloses them.
147
+
A **switch** statement can be nested. When nested, the**case** or **default** labels associate with the closest **switch** statement that encloses them.
146
148
147
-
**Microsoft Specific**
149
+
### Microsoft-specific behavior
148
150
149
-
Microsoft C does not limit the number of case values in a **switch** statement. The number is limited only by the available memory. ANSI C requires at least 257 case labels be allowed in a **switch** statement.
151
+
Microsoft C doesn't limit the number of **case** values in a **switch** statement. The number is limited only by the available memory. ANSI C requires at least 257 **case** labels be allowed in a **switch** statement.
150
152
151
153
The default for Microsoft C is that the Microsoft extensions are enabled. Use the [/Za](../build/reference/za-ze-disable-language-extensions.md) compiler option to disable these extensions.
0 commit comments