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
Primary expressions are the building blocks of more complex expressions. They may be constants, identifiers, and in C11, a [Generic selection](generic_selection.md). An expression in parentheses is also a primary expression.
9
+
Primary expressions are the building blocks of more complex expressions. They may be constants, identifiers, a [Generic selection](generic_selection.md), or an expression in parentheses.
Copy file name to clipboardExpand all lines: docs/c-language/data-type-specifiers-and-equivalents.md
+2-2Lines changed: 2 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -23,13 +23,13 @@ This documentation generally uses the forms of the type specifiers listed in the
23
23
|**`float`**| — |
24
24
|**`long double`**<sup>2</sup> | — |
25
25
26
-
<sup>1</sup> When you make the **`char`** type unsigned by default (by specifying the **`/J`** compiler option), you cannot abbreviate **`signed char`** as **`char`**.
26
+
<sup>1</sup> When you make the **`char`** type unsigned by default (by specifying the **`/J`** compiler option), you can't abbreviate **`signed char`** as **`char`**.
27
27
28
28
<sup>2</sup> In 32-bit and 64-bit operating systems, the Microsoft C compiler maps **`long double`** to type **`double`**.
29
29
30
30
**Microsoft specific**
31
31
32
-
You can specify the **`/J`** compiler option to change the default **`char`** type from **`signed char`** to **`unsigned char`**. When this option is in effect, **`char`** means the same as **`unsigned char`**, and you must use the **`signed`** keyword to declare a signed character value. If a **`char`** value is explicitly declared **`signed`**, the **`/J`** option does not affect it, and the value is sign-extended when widened to an **`int`** type. The **`char`** type is zero-extended when widened to **`int`** type.
32
+
You can specify the **`/J`** compiler option to change the default **`char`** type from **`signed char`** to **`unsigned char`**. When this option is in effect, **`char`** means the same as **`unsigned char`**, and you must use the **`signed`** keyword to declare a signed character value. If a **`char`** value is explicitly declared **`signed`**, the **`/J`** option doesn't affect it, and the value is sign-extended when widened to an **`int`** type. The **`char`** type is zero-extended when widened to **`int`** type.
Copy file name to clipboardExpand all lines: docs/c-language/generic_selection.md
+8-8Lines changed: 8 additions & 8 deletions
Original file line number
Diff line number
Diff line change
@@ -5,18 +5,18 @@ ms.date: "12/8/2020"
5
5
helpviewer_keywords: ["_Generic keyword [C]"]
6
6
---
7
7
8
-
# Generic Selection (C11)
8
+
# Generic selection (C11)
9
9
10
10
Use the **`_Generic`** keyword to write code that makes a compile-time decision based on the type of the argument.
11
11
12
-
**`_Generic`** selects an expression based on a type at compile time. It's similar to overloading in C++ where the type of the argument is used to select which function to call. In this case, the type of the argument selects which expression to evaluate.
12
+
**`_Generic`** selects an expression based on a type at compile time. It's similar to overloading in C++ where the type of the argument selects which function to call, except that the type of the argument selects which expression to evaluate.
13
13
14
-
For example, the expression `_Generic(42, int:"integer", char:"character", default:"unknown");` evaluates the type of `42` and looks for the matching type, `int` in the list. It will find it and return `"integer"`.
14
+
For example, the expression `_Generic(42, int:"integer", char:"character", default:"unknown");` evaluates the type of `42` and looks for the matching type, `int` in the list. It will find it and return `"integer"`.
@@ -40,7 +40,7 @@ Entries in the `assoc-list` that aren't chosen aren't evaluated.
40
40
41
41
## Example
42
42
43
-
One way to use **`_Generic`** is in a macro. The <tgmath.h> header file uses **_Generic** to call the right math function depending on the type of argument. For example, the macro for `cos()` maps a call with a float to `cosf()`, but a call with a complex double is mapped to `ccos()`.
43
+
One way to use **`_Generic`** is in a macro. The <tgmath.h> header file uses **_Generic** to call the right math function depending on the type of argument. For example, the macro for `cos()` maps a call with a float to `cosf()`, while mapping a call with a complex double to `ccos()`.
44
44
45
45
The following example shows how to write a macro that identifies the type of the argument you pass to it. It produces `"unknown"` if no entry in the *`assoc-list`* matches the controlling expression:
46
46
@@ -51,8 +51,8 @@ The following example shows how to write a macro that identifies the type of the
51
51
52
52
/* Get a type name string for the argument x */
53
53
#defineTYPE_NAME(X) _Generic((X), \
54
-
int: "int", \
55
-
char: "char", \
54
+
int: "int", \
55
+
char: "char", \
56
56
double: "double", \
57
57
default: "unknown")
58
58
@@ -63,7 +63,7 @@ int main()
63
63
// The following would result in a compile error because
64
64
// 42.4 is a double, doesn't match anything in the list,
0 commit comments