名稱空間
變體
操作

C 關鍵字

來自 cppreference.com
< c

這是 C 語言中的保留關鍵字列表。由於它們被語言使用,這些關鍵字不能被重新定義。作為例外,它們在屬性標記中不被視為保留(自 C23 起)

alignas (C23)
alignof (C23)
auto
bool (C23)
break
case
char
const
constexpr (C23)
continue
default
do
double
else
enum

extern
false (C23)
float
for
goto
if
inline (C99)
int
long
nullptr (C23)
register
restrict (C99)
return
short
signed

sizeof
static
static_assert (C23)
struct
switch
thread_local (C23)
true (C23)
typedef
typeof (C23)
typeof_unqual (C23)
union
unsigned
void
volatile
while

_Alignas (C11)(在 C23 中已棄用)
_Alignof (C11)(在 C23 中已棄用)
_Atomic (C11)
_BitInt (C23)
_Bool (C99)(在 C23 中已棄用)
_Complex (C99)
_Decimal128 (C23)
_Decimal32 (C23)
_Decimal64 (C23)
_Generic (C11)
_Imaginary (C99)
_Noreturn (C11)(在 C23 中已棄用)
_Static_assert (C11)(在 C23 中已棄用)
_Thread_local (C11)(在 C23 中已棄用)

以單下劃線開頭的最常見關鍵字通常透過它們的便捷宏使用

關鍵字 用作 定義於
_Alignas (C11)(在 C23 中已棄用) alignas (在 C23 中移除) stdalign.h
_Alignof (C11)(在 C23 中已棄用) alignof (在 C23 中移除) stdalign.h
_Atomic (C11) atomic_bool, atomic_int, ... stdatomic.h
_BitInt (C23) (無宏)
_Bool (C99)(在 C23 中已棄用) bool (在 C23 中移除) stdbool.h
_Complex (C99) complex complex.h
_Decimal128 (C23) (無宏)
_Decimal32 (C23) (無宏)
_Decimal64 (C23) (無宏)
_Generic (C11) (無宏)
_Imaginary (C99) imaginary complex.h
_Noreturn (C11)(在 C23 中已棄用) noreturn stdnoreturn.h
_Static_assert (C11)(在 C23 中已棄用) static_assert (在 C23 中移除) assert.h
_Thread_local (C11)(在 C23 中已棄用) thread_local (在 C23 中移除) threads.h

某些關鍵字已棄用,並保留為替代拼寫以保持相容性。它們可以在關鍵字可以使用的任何地方使用。

關鍵字 替代拼寫
alignas (C23) _Alignas (C11)(在 C23 中已棄用)
alignof (C23) _Alignof (C11)(在 C23 中已棄用)
bool (C23) _Bool (C99)(在 C23 中已棄用)
static_assert (C23) _Static_assert (C11)(在 C23 中已棄用)
thread_local (C23) _Thread_local (C11)(在 C23 中已棄用)

未指定這些關鍵字、它們的替代形式或 truefalse 的任何拼寫是否實現為預定義宏。

每個以雙下劃線 __ 或以單下劃線 _ 後跟大寫字母開頭的名稱都是保留的:詳見識別符號

請注意,三字元組 <%, %>, <:, :>, %:, 和 %:%: 提供了一種表示標準標記的替代方式

當它們在預處理器指令的上下文使用時,預處理器會識別以下標記

if
elif
else
endif

ifdef
ifndef
elifdef (C23)
elifndef (C23)
define
undef

include
embed (C23)
line
error
warning (C23)
pragma

defined
__has_include (C23)
__has_embed (C23)
__has_c_attribute (C23)

當它們在預處理器指令的上下文之外使用時,預處理器會識別以下標記

_Pragma (C99)

以下附加關鍵字被歸類為擴充套件並有條件地支援

asm
fortran

[編輯] 參考

  • C23 標準 (ISO/IEC 9899:2024)
  • 6.4.1 關鍵字 (p: 待定)
  • J.5.9 fortran 關鍵字 (p: 待定)
  • J.5.10 asm 關鍵字 (p: 待定)
  • C17 標準 (ISO/IEC 9899:2018)
  • 6.4.1 關鍵字 (p: 42-43)
  • J.5.9 fortran 關鍵字 (p: 422)
  • J.5.10 asm 關鍵字 (p: 422)
  • C11 標準 (ISO/IEC 9899:2011)
  • 6.4.1 關鍵字 (p: 58-59)
  • J.5.9 fortran 關鍵字 (p: 580)
  • J.5.10 asm 關鍵字 (p: 580)
  • C99 標準 (ISO/IEC 9899:1999)
  • 6.4.1 關鍵字 (p: 50)
  • J.5.9 fortran 關鍵字 (p: 514)
  • J.5.10 asm 關鍵字 (p: 514)
  • C89/C90 標準 (ISO/IEC 9899:1990)
  • 3.1.1 關鍵字
  • G.5.9 fortran 關鍵字
  • G.5.10 asm 關鍵字

[編輯] 參見

C++ 文件,關於C++ 關鍵字