Difference between revisions of "c/keyword"
(C has neither namespaces nor classes) |
YexuanXiao (Talk | contribs) (clarifying the status of deprecated keywords) |
||
(41 intermediate revisions by 14 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> | ||
{{rlt|char}}<br> | {{rlt|char}}<br> | ||
{{rlt|const}}<br> | {{rlt|const}}<br> | ||
+ | {{rlt|constexpr}} {{mark c23}}<br> | ||
{{rlt|continue}}<br> | {{rlt|continue}}<br> | ||
{{rlt|default}}<br> | {{rlt|default}}<br> | ||
Line 18: | 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> | ||
{{rlt|goto}}<br> | {{rlt|goto}}<br> | ||
{{rlt|if}}<br> | {{rlt|if}}<br> | ||
− | {{rlt|inline}} {{mark | + | {{rlt|inline}} {{mark c99}}<br> |
{{rlt|int}}<br> | {{rlt|int}}<br> | ||
{{rlt|long}}<br> | {{rlt|long}}<br> | ||
+ | {{rlt|nullptr}} {{mark c23}}<br> | ||
{{rlt|register}}<br> | {{rlt|register}}<br> | ||
− | {{rlt|restrict}} {{mark | + | {{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_unqual}} {{mark c23}}<br> | ||
{{rlt|union}}<br> | {{rlt|union}}<br> | ||
{{rlt|unsigned}}<br> | {{rlt|unsigned}}<br> | ||
{{rlt|void}}<br> | {{rlt|void}}<br> | ||
{{rlt|volatile}}<br> | {{rlt|volatile}}<br> | ||
− | {{rlt|while}} | + | {{rlt|while}}<br> |
| | | | ||
− | {{rlt|_Alignas}} {{mark | + | {{rlt|_Alignas}} {{mark c11}} {{mark deprecated c23}}<br> |
− | {{rlt|_Alignof}} {{mark | + | {{rlt|_Alignof}} {{mark c11}} {{mark deprecated c23}}<br> |
− | {{rlt|_Atomic}} {{mark | + | {{rlt|_Atomic}} {{mark c11}}<br> |
− | {{rlt|_Bool}} {{mark | + | {{rlt|_BitInt}} {{mark c23}}<br> |
− | {{rlt|_Complex}} {{mark | + | {{rlt|_Bool}} {{mark c99}} {{mark deprecated c23}}<br> |
− | {{rlt|_Generic}} {{mark | + | {{rlt|_Complex}} {{mark c99}}<br> |
− | {{rlt|_Imaginary}} {{mark | + | {{rlt|_Decimal128}} {{mark c23}}<br> |
− | {{rlt|_Noreturn}} {{mark | + | {{rlt|_Decimal32}} {{mark c23}}<br> |
− | {{rlt|_Static_assert}} {{mark | + | {{rlt|_Decimal64}} {{mark c23}}<br> |
− | {{rlt|_Thread_local}} {{mark | + | {{rlt|_Generic}} {{mark c11}}<br> |
+ | {{rlt|_Imaginary}} {{mark c99}}<br> | ||
+ | {{rlt|_Noreturn}} {{mark c11}} {{mark deprecated c23}}<br> | ||
+ | {{rlt|_Static_assert}} {{mark c11}} {{mark deprecated c23}}<br> | ||
+ | {{rlt|_Thread_local}} {{mark c11}} {{mark deprecated c23}}<br> | ||
|} | |} | ||
− | + | The most common keywords that begin with an underscore are generally used through their convenience macros: | |
+ | {|class="wikitable" | ||
+ | |- | ||
+ | |keyword | ||
+ | |used as | ||
+ | |defined in | ||
+ | |- | ||
+ | |{{rlt|_Alignas}} {{mark c11}} {{mark deprecated c23}} | ||
+ | |{{ltt|c/types|alignas}} {{mark until c23|removed=yes}} | ||
+ | |{{tt|stdalign.h}} | ||
+ | |- | ||
+ | |{{rlt|_Alignof}} {{mark c11}} {{mark deprecated c23}} | ||
+ | |{{ltt|c/types|alignof}} {{mark until c23|removed=yes}} | ||
+ | |{{tt|stdalign.h}} | ||
+ | |- | ||
+ | |{{rlt|_Atomic}} {{mark c11}} | ||
+ | |{{ltt|c/thread|atomic_bool, atomic_int, ...}} | ||
+ | |{{tt|stdatomic.h}} | ||
+ | |- | ||
+ | |{{rlt|_BitInt}} {{mark c23}} | ||
+ | |(no macro) | ||
+ | | | ||
+ | |- | ||
+ | |{{rlt|_Bool}} {{mark c99}} {{mark deprecated c23}} | ||
+ | |{{ltt|c/types|bool}} {{mark until c23|removed=yes}} | ||
+ | |{{tt|stdbool.h}} | ||
+ | |- | ||
+ | |{{rlt|_Complex}} {{mark c99}} | ||
+ | |{{ltt|c/numeric/complex/complex}} | ||
+ | |{{tt|complex.h}} | ||
+ | |- | ||
+ | |{{rlt|_Decimal128}} {{mark c23}} | ||
+ | |(no macro) | ||
+ | | | ||
+ | |- | ||
+ | |{{rlt|_Decimal32}} {{mark c23}} | ||
+ | |(no macro) | ||
+ | | | ||
+ | |- | ||
+ | |{{rlt|_Decimal64}} {{mark c23}} | ||
+ | |(no macro) | ||
+ | | | ||
+ | |- | ||
+ | |{{rlt|_Generic}} {{mark c11}} | ||
+ | |(no macro) | ||
+ | | | ||
+ | |- | ||
+ | |{{rlt|_Imaginary}} {{mark c99}} | ||
+ | |{{ltt|c/numeric/complex/imaginary}} | ||
+ | |{{tt|complex.h}} | ||
+ | |- | ||
+ | |{{rlt|_Noreturn}} {{mark c11}} {{mark deprecated c23}} | ||
+ | |{{ltt|c/types|noreturn}} | ||
+ | |{{tt|stdnoreturn.h}} | ||
+ | |- | ||
+ | |{{rlt|_Static_assert}} {{mark c11}} {{mark deprecated c23}} | ||
+ | |{{ltt|c/error/static_assert}} {{mark until c23|removed=yes}} | ||
+ | |{{tt|assert.h}} | ||
+ | |- | ||
+ | |{{rlt|_Thread_local}} {{mark c11}} {{mark deprecated c23}} | ||
+ | |{{ltt|c/thread/thread_local}} {{mark until c23|removed=yes}} | ||
+ | |{{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]]. | ||
− | [[ | + | The following tokens are recognized by the [[c/preprocessor|preprocessor]] when they are used ''within'' the context of a preprocessor directive: |
− | + | {|class="wikitable" | |
− | + | |- | |
− | + | | | |
− | + | {{ltt|c/preprocessor/conditional|if}}<br> | |
− | + | {{ltt|c/preprocessor/conditional|elif}}<br> | |
− | + | {{ltt|c/preprocessor/conditional|else}}<br> | |
− | + | {{ltt|c/preprocessor/conditional|endif}}<br> | |
+ | | | ||
+ | {{ltt|c/preprocessor/conditional|ifdef}}<br> | ||
+ | {{ltt|c/preprocessor/conditional|ifndef}}<br> | ||
+ | {{ltt|c/preprocessor/conditional|elifdef}} {{mark c23}}<br> | ||
+ | {{ltt|c/preprocessor/conditional|elifndef}} {{mark c23}}<br> | ||
+ | {{ltt|c/preprocessor/replace|define}}<br> | ||
+ | {{ltt|c/preprocessor/replace|undef}}<br> | ||
+ | | | ||
+ | {{ltt|c/preprocessor/include|include}}<br> | ||
+ | {{ltt|c/preprocessor/embed|embed}} {{mark c23}}<br> | ||
+ | {{ltt|c/preprocessor/line|line}}<br> | ||
+ | {{ltt|c/preprocessor/error|error}}<br> | ||
+ | {{ltt|c/preprocessor/error|warning}} {{mark c23}}<br> | ||
+ | {{ltt|c/preprocessor/impl|pragma}}<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}} | ||
+ | |} | ||
+ | |||
+ | The following tokens are recognized by the preprocessor when they are used ''outside'' the context of a preprocessor directive: | ||
+ | {|class="wikitable" | ||
+ | |- | ||
+ | | | ||
+ | {{ltt|c/preprocessor/impl|_Pragma}} {{mark c99}} | ||
+ | |} | ||
+ | |||
+ | The following additional keywords are classified as extensions and conditionally-supported: | ||
+ | {|class="wikitable" | ||
+ | |- | ||
+ | | | ||
+ | {{ltt|c/language/asm|asm}}<br> | ||
+ | {{rlt|fortran}} | ||
+ | |} | ||
+ | |||
+ | ===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|section=6.4.1|title=Keywords|p=42-43}} | ||
+ | {{ref std|section=J.5.9|title=The fortran keyword|p=422}} | ||
+ | {{ref std|section=J.5.10|title=The asm keyword|p=422}} | ||
+ | {{ref std end}} | ||
+ | {{ref std c11}} | ||
+ | {{ref std|section=6.4.1|title=Keywords|p=58-59}} | ||
+ | {{ref std|section=J.5.9|title=The fortran keyword|p=580}} | ||
+ | {{ref std|section=J.5.10|title=The asm keyword|p=580}} | ||
+ | {{ref std end}} | ||
+ | {{ref std c99}} | ||
+ | {{ref std|section=6.4.1|title=Keywords|p=50}} | ||
+ | {{ref std|section=J.5.9|title=The fortran keyword|p=514}} | ||
+ | {{ref std|section=J.5.10|title=The asm keyword|p=514}} | ||
+ | {{ref std end}} | ||
+ | {{ref std c89}} | ||
+ | {{ref std|section=3.1.1|title=Keywords}} | ||
+ | {{ref std|section=G.5.9|title=The fortran keyword}} | ||
+ | {{ref std|section=G.5.10|title=The asm keyword}} | ||
+ | {{ref std end}} | ||
+ | |||
+ | ===See also=== | ||
+ | {{dsc begin}} | ||
+ | {{dsc see cpp|cpp/keyword|C++ keywords|nomono=true}} | ||
+ | {{dsc end}} | ||
+ | |||
+ | {{langlinks|ar|cs|de|es|fr|it|ja|ko|pl|pt|ru|tr|zh}} |
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
|