C 关键字C Keywords

“关键字”是对 C 编译器具有特殊含义的单词。"Keywords" are words that have special meaning to the C compiler. 在翻译的第 7 和第 8 阶段中,标识符不能具有与 C 关键字相同的拼写和大小写。In translation phases 7 and 8, an identifier cannot have the same spelling and case as a C keyword. (请参阅《预处理器参考》中的翻译阶段的说明;有关标识符的信息,请参阅标识符。)C 语言使用下列关键字:(See a description of translation phases in the Preprocessor Reference; for information on identifiers, see Identifiers.) The C language uses the following keywords:

autoauto doubledouble intint structstruct
breakbreak elseelse longlong switchswitch
casecase enumenum registerregister typedeftypedef
charchar externextern returnreturn unionunion
constconst floatfloat shortshort unsignedunsigned
continuecontinue forfor signedsigned voidvoid
defaultdefault gotogoto sizeofsizeof volatilevolatile
dodo ifif staticstatic whilewhile

您不能重新定义关键字。You cannot redefine keywords. 但是,你可在使用 C 预处理器指令编译之前指定关键字的替换文本。However, you can specify text to be substituted for keywords before compilation by using C preprocessor directives.

Microsoft 专用Microsoft Specific

ANSI C 标准允许为了编译器实现保留带有两个前导下划线的标识符。The ANSI C standard allows identifiers with two leading underscores to be reserved for compiler implementations. 因此,Microsoft 约定的是在 Microsoft 专用关键字名称前放置双下划线。Therefore, the Microsoft convention is to precede Microsoft-specific keyword names with double underscores. 这些单词不能用作标识符名称。These words cannot be used as identifier names. 有关命名标识符的 ANSI 规则的描述,包括双下划线的使用,请参阅标识符For a description of the ANSI rules for naming identifiers, including the use of double underscores, see Identifiers.

下列关键字和特殊标识符由 Microsoft C 编译器识别:The following keywords and special identifiers are recognized by the Microsoft C compiler:

__asm__asm dllimport2dllimport2 __int8__int8 naked2naked2
__based1__based1 __except__except __int16__int16 __stdcall__stdcall
__cdecl__cdecl __fastcall__fastcall __int32__int32 thread2thread2
__declspec__declspec __finally__finally __int64__int64 __try__try
dllexport2dllexport2 __inline__inline __leave__leave
  1. __based 关键字对于 32 位和 64 位目标编译的使用会受到限制。The __based keyword has limited uses for 32-bit and 64-bit target compilations.

  2. 这些关键字在与 __declspec 一起使用时是特殊标识符;它们在其他上下文中的使用不受限制。These are special identifiers when used with __declspec; their use in other contexts is not restricted.

    默认情况下将启用 Microsoft 扩展。Microsoft extensions are enabled by default. 若要确保您的程序是完全可移植的,可通过在编译期间指定 /Za 选项(针对 ANSI 兼容性编译)来禁用 Microsoft 扩展。To ensure that your programs are fully portable, you can disable Microsoft extensions by specifying the /Za option (compile for ANSI compatibility) during compilation. 如果这样做,将禁用 Microsoft 专用关键字。When you do this, Microsoft-specific keywords are disabled.

    启用 Microsoft 扩展时,您可在程序中使用上面列出的关键字。When Microsoft extensions are enabled, you can use the keywords listed above in your programs. 为了兼容 ANSI,这其中大部分关键字以一个双下划线开头。For ANSI compliance, most of these keywords are prefaced by a double underscore. dllexportdllimportnakedthread 这 4 个关键字除外,它们仅与 __declspec 一起使用,因此无需前导双下划线。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.

    结束 Microsoft 专用END Microsoft Specific

请参阅See Also

C 的元素Elements of C