|
1 | 1 | --- |
2 | 2 | title: "C Keywords" |
3 | | -ms.date: "10/09/2018" |
| 3 | +description: "Keywords in Standard C and Microsoft C compiler extensions." |
| 4 | +ms.date: 09/12/2020 |
4 | 5 | helpviewer_keywords: ["keywords [C]", "redefining keywords", "Microsoft-specific keywords"] |
5 | 6 | ms.assetid: 2d932335-97bf-45cd-b367-4ae00db0ff42 |
6 | 7 | --- |
7 | 8 | # C Keywords |
8 | 9 |
|
9 | | -"Keywords" are words that have special meaning to the C compiler. In translation phases 7 and 8, an identifier cannot have the same spelling and case as a C keyword. (See a description of [translation phases](../preprocessor/phases-of-translation.md) in the *Preprocessor Reference*; for information on identifiers, see [Identifiers](../c-language/c-identifiers.md).) The C language uses the following keywords: |
| 10 | +*Keywords* are words that have special meaning to the C compiler. In translation phases 7 and 8, an identifier can't have the same spelling and case as a C keyword. For more information, see [translation phases](../preprocessor/phases-of-translation.md) in the *Preprocessor Reference*. For more information on identifiers, see [Identifiers](../c-language/c-identifiers.md). |
| 11 | + |
| 12 | +## Standard C keywords |
| 13 | + |
| 14 | +The C language uses the following keywords: |
10 | 15 |
|
11 | 16 | :::row::: |
12 | 17 | :::column::: |
13 | 18 | **`auto`**\ |
14 | | - **`double`**\ |
15 | | - **`int`**\ |
16 | | - **`struct`**\ |
17 | 19 | **`break`**\ |
18 | | - **`else`**\ |
19 | | - **`long`**\ |
20 | | - **`switch`** |
21 | | - :::column-end::: |
22 | | - :::column::: |
23 | 20 | **`case`**\ |
24 | | - **`enum`**\ |
25 | | - **`register`**\ |
26 | | - **`typedef`**\ |
27 | 21 | **`char`**\ |
28 | | - **`extern`**\ |
29 | | - **`return`**\ |
30 | | - **`union`** |
| 22 | + **`const`**\ |
| 23 | + **`continue`**\ |
| 24 | + **`default`**\ |
| 25 | + **`do`**\ |
| 26 | + **`double`**\ |
| 27 | + **`else`**\ |
| 28 | + **`enum`** |
31 | 29 | :::column-end::: |
32 | 30 | :::column::: |
33 | | - **`const`**\ |
| 31 | + **`extern`**\ |
34 | 32 | **`float`**\ |
35 | | - **`short`**\ |
36 | | - **`unsigned`**\ |
37 | | - **`continue`**\ |
38 | 33 | **`for`**\ |
39 | | - **`signed`**\ |
40 | | - **`void`** |
| 34 | + **`goto`**\ |
| 35 | + **`if`**\ |
| 36 | + **`inline`** <sup>1, a</sup>\ |
| 37 | + **`int`**\ |
| 38 | + **`long`**\ |
| 39 | + **`register`**\ |
| 40 | + **`restrict`** <sup>1, a</sup>\ |
| 41 | + **`return`** |
41 | 42 | :::column-end::: |
42 | 43 | :::column::: |
43 | | - **`default`**\ |
44 | | - **`goto`**\ |
| 44 | + **`short`**\ |
| 45 | + **`signed`**\ |
45 | 46 | **`sizeof`**\ |
46 | | - **`volatile`**\ |
47 | | - **`do`**\ |
48 | | - **`if`**\ |
49 | 47 | **`static`**\ |
50 | | - **`while`** |
| 48 | + **`struct`**\ |
| 49 | + **`switch`**\ |
| 50 | + **`typedef`**\ |
| 51 | + **`union`**\ |
| 52 | + **`unsigned`**\ |
| 53 | + **`void`**\ |
| 54 | + **`volatile`** |
| 55 | + :::column-end::: |
| 56 | + :::column::: |
| 57 | + **`while`**\ |
| 58 | + **`_Alignas`** <sup>2, a</sup>\ |
| 59 | + **`_Alignof`** <sup>2, a</sup>\ |
| 60 | + **`_Atomic`** <sup>2, b</sup>\ |
| 61 | + **`_Bool`** <sup>1, a</sup>\ |
| 62 | + **`_Complex`** <sup>1, b</sup>\ |
| 63 | + **`_Generic`** <sup>2, a</sup>\ |
| 64 | + **`_Imaginary`** <sup>1, b</sup>\ |
| 65 | + **`_Noreturn`** <sup>2, a</sup>\ |
| 66 | + **`_Static_assert`** <sup>2, a</sup>\ |
| 67 | + **`_Thread_local`** <sup>2, b</sup> |
51 | 68 | :::column-end::: |
52 | 69 | :::row-end::: |
53 | 70 |
|
54 | | -You can't redefine keywords. However, you can specify text to be substituted for keywords before compilation by using C [preprocessor directives](../preprocessor/preprocessor-directives.md). |
| 71 | +<sup>1</sup> Keywords introduced in ISO C99. |
55 | 72 |
|
56 | | -**Microsoft Specific** |
| 73 | +<sup>2</sup> Keywords introduced in ISO C11. |
57 | 74 |
|
58 | | -The ANSI C standard allows identifiers with two leading underscores to be reserved for compiler implementations. Therefore, the Microsoft convention is to precede Microsoft-specific keyword names with double underscores. These words cannot be used as identifier names. For a description of the ANSI rules for naming identifiers, including the use of double underscores, see [Identifiers](../c-language/c-identifiers.md). |
| 75 | +<sup>a</sup> Starting in Visual Studio 2019 version 16.8, these keywords are supported in code compiled as C when the **`/std:c11`** or **`/std:c17`** compiler options are specified. |
| 76 | + |
| 77 | +<sup>b</sup> Starting in Visual Studio 2019 version 16.8, these keywords are recognized but not supported by the compiler in code compiled as C when the **`/std:c11`** or **`/std:c17`** compiler options are specified. |
| 78 | + |
| 79 | +You can't redefine keywords. However, you can specify text to replace keywords before compilation by using C [preprocessor directives](../preprocessor/preprocessor-directives.md). |
| 80 | + |
| 81 | +## Microsoft-specific C keywords |
| 82 | + |
| 83 | +The ANSI and ISO C standards allow identifiers with two leading underscores to be reserved for compiler implementations. The Microsoft convention is to precede Microsoft-specific keyword names with double underscores. These words can't be used as identifier names. For a description of the rules for naming identifiers, including the use of double underscores, see [Identifiers](../c-language/c-identifiers.md). |
59 | 84 |
|
60 | 85 | The following keywords and special identifiers are recognized by the Microsoft C compiler: |
61 | 86 |
|
62 | 87 | :::row::: |
63 | 88 | :::column::: |
64 | | - **`__asm`**<sup>3</sup>\ |
65 | | - **`dllimport`**<sup>2</sup>\ |
66 | | - **`__int8`**<sup>3</sup>\ |
67 | | - **`naked`**<sup>2</sup>\ |
68 | | - **`__based`**<sup>1, 3</sup> |
| 89 | + **`__asm`**<sup>5</sup>\ |
| 90 | + **`dllimport`**<sup>4</sup>\ |
| 91 | + **`__int8`**<sup>5</sup>\ |
| 92 | + **`naked`**<sup>4</sup>\ |
| 93 | + **`__based`**<sup>3, 5</sup> |
69 | 94 | :::column-end::: |
70 | 95 | :::column::: |
71 | | - **`__except`**<sup>3</sup>\ |
72 | | - **`__int16`**<sup>3</sup>\ |
73 | | - **`__stdcall`**<sup>3</sup>\ |
74 | | - **`__cdecl`**<sup>3</sup>\ |
| 96 | + **`__except`**<sup>5</sup>\ |
| 97 | + **`__int16`**<sup>5</sup>\ |
| 98 | + **`__stdcall`**<sup>5</sup>\ |
| 99 | + **`__cdecl`**<sup>5</sup>\ |
75 | 100 | **`__fastcall`** |
76 | 101 | :::column-end::: |
77 | 102 | :::column::: |
78 | | - **`__int32`**<sup>3</sup>\ |
79 | | - **`thread`**<sup>2</sup>\ |
80 | | - **`__declspec`**<sup>3</sup>\ |
81 | | - **`__finally`**<sup>3</sup>\ |
82 | | - **`__int64`**<sup>3</sup> |
| 103 | + **`__int32`**<sup>5</sup>\ |
| 104 | + **`thread`**<sup>4</sup>\ |
| 105 | + **`__declspec`**<sup>5</sup>\ |
| 106 | + **`__finally`**<sup>5</sup>\ |
| 107 | + **`__int64`**<sup>5</sup> |
83 | 108 | :::column-end::: |
84 | 109 | :::column::: |
85 | | - **`__try`**<sup>3</sup>\ |
86 | | - **`dllexport`**<sup>2</sup>\ |
87 | | - **`__inline`**<sup>3</sup>\ |
88 | | - **`__leave`**<sup>3</sup> |
| 110 | + **`__try`**<sup>5</sup>\ |
| 111 | + **`dllexport`**<sup>4</sup>\ |
| 112 | + **`__inline`**<sup>5</sup>\ |
| 113 | + **`__leave`**<sup>5</sup> |
89 | 114 | :::column-end::: |
90 | 115 | :::row-end::: |
91 | 116 |
|
92 | | -<sup>1</sup> The **`__based`** keyword has limited uses for 32-bit and 64-bit target compilations. |
93 | | - |
94 | | -<sup>2</sup> These are special identifiers when used with **`__declspec`**; their use in other contexts is not restricted. |
| 117 | +<sup>3</sup> The **`__based`** keyword has limited uses for 32-bit and 64-bit target compilations. |
95 | 118 |
|
96 | | -<sup>3</sup> For compatibility with previous versions, these keywords are available both with two leading underscores and a single leading underscore when Microsoft extensions are enabled. |
| 119 | +<sup>4</sup> These are special identifiers when used with **`__declspec`**; their use in other contexts is unrestricted. |
97 | 120 |
|
98 | | -Microsoft extensions are enabled by default. To ensure that your programs are fully portable, you can disable Microsoft extensions by specifying the [/Za \(Disable language extensions)](../build/reference/za-ze-disable-language-extensions.md) option during compilation. When you do this, some Microsoft-specific keywords are disabled. |
| 121 | +<sup>5</sup> For compatibility with previous versions, these keywords are available both with two leading underscores and a single leading underscore when Microsoft extensions are enabled. |
99 | 122 |
|
100 | | -When Microsoft extensions are enabled, you can use the keywords listed above in your programs. For ANSI compliance, most of these keywords are prefaced by a double underscore. The four exceptions, **`dllexport`**, **`dllimport`**, **`naked`**, and **`thread`**, are used only with **`__declspec`** and therefore do not require a leading double underscore. For backward compatibility, single-underscore versions of the rest of the keywords are supported. |
| 123 | +Microsoft extensions are enabled by default. To assist in creating portable code, you can disable Microsoft extensions by specifying the [/Za \(Disable language extensions)](../build/reference/za-ze-disable-language-extensions.md) option during compilation. When you use this option, some Microsoft-specific keywords are disabled. |
101 | 124 |
|
102 | | -**END Microsoft Specific** |
| 125 | +When Microsoft extensions are enabled, you can use the keywords listed above in your programs. For standards compliance, most of these keywords are prefaced by a double underscore. The four exceptions, **`dllexport`**, **`dllimport`**, **`naked`**, and **`thread`**, are used only with **`__declspec`** and don't require a leading double underscore. For backward compatibility, single-underscore versions of the rest of the keywords are supported. |
103 | 126 |
|
104 | 127 | ## See also |
105 | 128 |
|
|
0 commit comments