Difference between revisions of "c/keyword"
Omarsaber98 (Talk | contribs) m (added new c23 keywords) |
YexuanXiao (Talk | contribs) (clarifying the status of deprecated keywords) |
||
(9 intermediate revisions by 6 users not shown) | |||
Line 2: | Line 2: | ||
{{c/keyword/navbar}} | {{c/keyword/navbar}} | ||
− | This is a list of reserved keywords in C. Since they are used by the language, these keywords are not available for re-definition. | + | This is a list of reserved keywords in C. Since they are used by the language, these keywords are not available for re-definition. {{rev inl|since=c23|As an exception, they are not considered reserved in [[c/language/attributes|{{spar|attribute-token}}]]s}} |
{|class="wikitable" | {|class="wikitable" | ||
|- | |- | ||
| | | | ||
+ | {{rlt|alignas}} {{mark c23}}<br> | ||
+ | {{rlt|alignof}} {{mark c23}}<br> | ||
{{rlt|auto}}<br> | {{rlt|auto}}<br> | ||
+ | {{rlt|bool}} {{mark c23}}<br> | ||
{{rlt|break}}<br> | {{rlt|break}}<br> | ||
{{rlt|case}}<br> | {{rlt|case}}<br> | ||
Line 19: | Line 22: | ||
{{rlt|else}}<br> | {{rlt|else}}<br> | ||
{{rlt|enum}}<br> | {{rlt|enum}}<br> | ||
− | |||
| | | | ||
+ | {{rlt|extern}}<br> | ||
+ | {{rlt|false}} {{mark c23}}<br> | ||
{{rlt|float}}<br> | {{rlt|float}}<br> | ||
{{rlt|for}}<br> | {{rlt|for}}<br> | ||
Line 32: | Line 36: | ||
{{rlt|restrict}} {{mark c99}}<br> | {{rlt|restrict}} {{mark c99}}<br> | ||
{{rlt|return}}<br> | {{rlt|return}}<br> | ||
− | {{rlt|short}} | + | {{rlt|short}}<br> |
− | + | ||
{{rlt|signed}}<br> | {{rlt|signed}}<br> | ||
+ | | | ||
{{rlt|sizeof}}<br> | {{rlt|sizeof}}<br> | ||
{{rlt|static}}<br> | {{rlt|static}}<br> | ||
+ | {{rlt|static_assert}} {{mark c23}}<br> | ||
{{rlt|struct}}<br> | {{rlt|struct}}<br> | ||
{{rlt|switch}}<br> | {{rlt|switch}}<br> | ||
+ | {{rlt|thread_local}} {{mark c23}}<br> | ||
+ | {{rlt|true}} {{mark c23}}<br> | ||
{{rlt|typedef}}<br> | {{rlt|typedef}}<br> | ||
{{rlt|typeof}} {{mark c23}}<br> | {{rlt|typeof}} {{mark c23}}<br> | ||
Line 46: | Line 53: | ||
{{rlt|void}}<br> | {{rlt|void}}<br> | ||
{{rlt|volatile}}<br> | {{rlt|volatile}}<br> | ||
− | {{rlt|while}} | + | {{rlt|while}}<br> |
| | | | ||
− | {{rlt|_Alignas}} {{mark c11}}<br> | + | {{rlt|_Alignas}} {{mark c11}} {{mark deprecated c23}}<br> |
− | {{rlt|_Alignof}} {{mark c11}}<br> | + | {{rlt|_Alignof}} {{mark c11}} {{mark deprecated c23}}<br> |
{{rlt|_Atomic}} {{mark c11}}<br> | {{rlt|_Atomic}} {{mark c11}}<br> | ||
{{rlt|_BitInt}} {{mark c23}}<br> | {{rlt|_BitInt}} {{mark c23}}<br> | ||
− | {{rlt|_Bool}} {{mark c99}}<br> | + | {{rlt|_Bool}} {{mark c99}} {{mark deprecated c23}}<br> |
{{rlt|_Complex}} {{mark c99}}<br> | {{rlt|_Complex}} {{mark c99}}<br> | ||
{{rlt|_Decimal128}} {{mark c23}}<br> | {{rlt|_Decimal128}} {{mark c23}}<br> | ||
Line 59: | Line 66: | ||
{{rlt|_Generic}} {{mark c11}}<br> | {{rlt|_Generic}} {{mark c11}}<br> | ||
{{rlt|_Imaginary}} {{mark c99}}<br> | {{rlt|_Imaginary}} {{mark c99}}<br> | ||
− | {{rlt|_Noreturn}} {{mark c11}}<br> | + | {{rlt|_Noreturn}} {{mark c11}} {{mark deprecated c23}}<br> |
− | {{rlt|_Static_assert}} {{mark c11}}<br> | + | {{rlt|_Static_assert}} {{mark c11}} {{mark deprecated c23}}<br> |
− | {{rlt|_Thread_local}} {{mark c11}} | + | {{rlt|_Thread_local}} {{mark c11}} {{mark deprecated c23}}<br> |
|} | |} | ||
Line 71: | Line 78: | ||
|defined in | |defined in | ||
|- | |- | ||
− | |{{rlt|_Alignas}} {{mark c11}} | + | |{{rlt|_Alignas}} {{mark c11}} {{mark deprecated c23}} |
− | |{{ltt|c/types|alignas}} | + | |{{ltt|c/types|alignas}} {{mark until c23|removed=yes}} |
|{{tt|stdalign.h}} | |{{tt|stdalign.h}} | ||
|- | |- | ||
− | |{{rlt|_Alignof}} {{mark c11}} | + | |{{rlt|_Alignof}} {{mark c11}} {{mark deprecated c23}} |
− | |{{ltt|c/types|alignof}} | + | |{{ltt|c/types|alignof}} {{mark until c23|removed=yes}} |
|{{tt|stdalign.h}} | |{{tt|stdalign.h}} | ||
|- | |- | ||
Line 83: | Line 90: | ||
|{{tt|stdatomic.h}} | |{{tt|stdatomic.h}} | ||
|- | |- | ||
− | |{{rlt|_Bool}} {{mark c99}} | + | |{{rlt|_BitInt}} {{mark c23}} |
− | |{{ltt|c/types|bool}} | + | |(no macro) |
+ | | | ||
+ | |- | ||
+ | |{{rlt|_Bool}} {{mark c99}} {{mark deprecated c23}} | ||
+ | |{{ltt|c/types|bool}} {{mark until c23|removed=yes}} | ||
|{{tt|stdbool.h}} | |{{tt|stdbool.h}} | ||
|- | |- | ||
Line 111: | Line 122: | ||
|{{tt|complex.h}} | |{{tt|complex.h}} | ||
|- | |- | ||
− | |{{rlt|_Noreturn}} {{mark c11}} | + | |{{rlt|_Noreturn}} {{mark c11}} {{mark deprecated c23}} |
|{{ltt|c/types|noreturn}} | |{{ltt|c/types|noreturn}} | ||
|{{tt|stdnoreturn.h}} | |{{tt|stdnoreturn.h}} | ||
|- | |- | ||
− | |{{rlt|_Static_assert}} {{mark c11}} | + | |{{rlt|_Static_assert}} {{mark c11}} {{mark deprecated c23}} |
− | |{{ltt|c/error/static_assert}} | + | |{{ltt|c/error/static_assert}} {{mark until c23|removed=yes}} |
|{{tt|assert.h}} | |{{tt|assert.h}} | ||
|- | |- | ||
− | |{{rlt|_Thread_local}} {{mark c11}} | + | |{{rlt|_Thread_local}} {{mark c11}} {{mark deprecated c23}} |
− | |{{ltt|c/thread/thread_local}} | + | |{{ltt|c/thread/thread_local}} {{mark until c23|removed=yes}} |
|{{tt|threads.h}} | |{{tt|threads.h}} | ||
|} | |} | ||
− | + | <!-- begin c23 --> | |
+ | Some keywords are deprecated and retained as alternative spellings for compatibility purposes. These can be used wherever the keyword can. | ||
+ | {|class="wikitable" | ||
+ | |- | ||
+ | |keyword | ||
+ | |alternative spelling | ||
+ | |- | ||
+ | |{{tt|alignas}} {{mark c23}} | ||
+ | |{{tt|_Alignas}} {{mark c11}} {{mark deprecated c23}} | ||
+ | |- | ||
+ | |{{tt|alignof}} {{mark c23}} | ||
+ | |{{tt|_Alignof}} {{mark c11}} {{mark deprecated c23}} | ||
+ | |- | ||
+ | |{{tt|bool}} {{mark c23}} | ||
+ | |{{tt|_Bool}} {{mark c99}} {{mark deprecated c23}} | ||
+ | |- | ||
+ | |{{tt|static_assert}} {{mark c23}} | ||
+ | |{{tt|_Static_assert}} {{mark c11}} {{mark deprecated c23}} | ||
+ | |- | ||
+ | |{{tt|thread_local}} {{mark c23}} | ||
+ | |{{tt|_Thread_local}} {{mark c11}} {{mark deprecated c23}} | ||
+ | |} | ||
+ | |||
+ | It is unspecified whether any of the spellings of these keywords, their alternate forms, or {{tt|true}} and {{tt|false}} is implemented as a predefined macro. | ||
+ | <!-- end c23 --> | ||
+ | |||
+ | Each name that begins with a double underscore {{ttb|__}} or an underscore {{ttb|_}} followed by an uppercase letter is reserved: see [[c/language/identifier#Reserved_identifiers|identifier]] for details. | ||
Note that digraphs {{tt|<%}}, {{tt|%>}}, {{tt|<:}}, {{tt|:>}}, {{tt|%:}}, and {{tt|%:%:}} provide an [[c/language/operator_alternative|alternative way to represent standard tokens]]. | Note that digraphs {{tt|<%}}, {{tt|%>}}, {{tt|<:}}, {{tt|:>}}, {{tt|%:}}, and {{tt|%:%:}} provide an [[c/language/operator_alternative|alternative way to represent standard tokens]]. | ||
Line 145: | Line 182: | ||
| | | | ||
{{ltt|c/preprocessor/include|include}}<br> | {{ltt|c/preprocessor/include|include}}<br> | ||
+ | {{ltt|c/preprocessor/embed|embed}} {{mark c23}}<br> | ||
{{ltt|c/preprocessor/line|line}}<br> | {{ltt|c/preprocessor/line|line}}<br> | ||
{{ltt|c/preprocessor/error|error}}<br> | {{ltt|c/preprocessor/error|error}}<br> | ||
Line 151: | Line 189: | ||
| | | | ||
{{ltt|c/preprocessor/conditional|defined}}<br> | {{ltt|c/preprocessor/conditional|defined}}<br> | ||
+ | {{ltt|c/preprocessor/include|__has_include}} {{mark c23}}<br> | ||
+ | {{ltt|c/preprocessor/embed|__has_embed}} {{mark c23}}<br> | ||
{{ltt|c/language/attributes#Attribute_testing|__has_c_attribute}} {{mark c23}} | {{ltt|c/language/attributes#Attribute_testing|__has_c_attribute}} {{mark c23}} | ||
|} | |} | ||
Line 170: | Line 210: | ||
===References=== | ===References=== | ||
+ | {{ref std c23}} | ||
+ | {{ref std|section=6.4.1|title=Keywords|p=TBD}} | ||
+ | {{ref std|section=J.5.9|title=The fortran keyword|p=TBD}} | ||
+ | {{ref std|section=J.5.10|title=The asm keyword|p=TBD}} | ||
+ | {{ref std end}} | ||
{{ref std c17}} | {{ref std c17}} | ||
{{ref std|section=6.4.1|title=Keywords|p=42-43}} | {{ref std|section=6.4.1|title=Keywords|p=42-43}} |
Latest revision as of 00:37, 8 November 2024
This is a list of reserved keywords in C. Since they are used by the language, these keywords are not available for re-definition. As an exception, they are not considered reserved in attribute-tokens(since C23)
|
|
|
|
The most common keywords that begin with an underscore are generally used through their convenience macros:
keyword | used as | defined in |
_Alignas (C11) (deprecated in C23)
|
alignas (removed in C23) | stdalign.h
|
_Alignof (C11) (deprecated in C23)
|
alignof (removed in C23) | stdalign.h
|
_Atomic (C11)
|
atomic_bool, atomic_int, ... | stdatomic.h
|
_BitInt (C23)
|
(no macro) | |
_Bool (C99) (deprecated in C23)
|
bool (removed in C23) | stdbool.h
|
_Complex (C99)
|
complex | complex.h
|
_Decimal128 (C23)
|
(no macro) | |
_Decimal32 (C23)
|
(no macro) | |
_Decimal64 (C23)
|
(no macro) | |
_Generic (C11)
|
(no macro) | |
_Imaginary (C99)
|
imaginary | complex.h
|
_Noreturn (C11) (deprecated in C23)
|
noreturn | stdnoreturn.h
|
_Static_assert (C11) (deprecated in C23)
|
static_assert (removed in C23) | assert.h
|
_Thread_local (C11) (deprecated in C23)
|
thread_local (removed in C23) | threads.h
|
Some keywords are deprecated and retained as alternative spellings for compatibility purposes. These can be used wherever the keyword can.
keyword | alternative spelling |
alignas (C23)
|
_Alignas (C11) (deprecated in C23)
|
alignof (C23)
|
_Alignof (C11) (deprecated in C23)
|
bool (C23)
|
_Bool (C99) (deprecated in C23)
|
static_assert (C23)
|
_Static_assert (C11) (deprecated in C23)
|
thread_local (C23)
|
_Thread_local (C11) (deprecated in C23)
|
It is unspecified whether any of the spellings of these keywords, their alternate forms, or true
and false
is implemented as a predefined macro.
Each name that begins with a double underscore __
or an underscore _
followed by an uppercase letter is reserved: see identifier for details.
Note that digraphs <%
, %>
, <:
, :>
, %:
, and %:%:
provide an alternative way to represent standard tokens.
The following tokens are recognized by the preprocessor when they are used within the context of a preprocessor directive:
defined |
The following tokens are recognized by the preprocessor when they are used outside the context of a preprocessor directive:
_Pragma (C99) |
The following additional keywords are classified as extensions and conditionally-supported:
[edit] References
- C23 standard (ISO/IEC 9899:2024):
- 6.4.1 Keywords (p: TBD)
- J.5.9 The fortran keyword (p: TBD)
- J.5.10 The asm keyword (p: TBD)
- C17 standard (ISO/IEC 9899:2018):
- 6.4.1 Keywords (p: 42-43)
- J.5.9 The fortran keyword (p: 422)
- J.5.10 The asm keyword (p: 422)
- C11 standard (ISO/IEC 9899:2011):
- 6.4.1 Keywords (p: 58-59)
- J.5.9 The fortran keyword (p: 580)
- J.5.10 The asm keyword (p: 580)
- C99 standard (ISO/IEC 9899:1999):
- 6.4.1 Keywords (p: 50)
- J.5.9 The fortran keyword (p: 514)
- J.5.10 The asm keyword (p: 514)
- C89/C90 standard (ISO/IEC 9899:1990):
- 3.1.1 Keywords
- G.5.9 The fortran keyword
- G.5.10 The asm keyword
[edit] See also
C++ documentation for C++ keywords
|