C++ 关键字
关键字是具有特殊意义的预定义保留标识符。 它们不能用作程序中的标识符。 Microsoft C++ 保留了下列关键字。 带前导下划线的名称是 Microsoft 扩展。
__box 2 |
||
__gc 2 |
||
__hook 3 |
||
__nogc 2 |
||
__pin 2 |
||
__sealed 2 |
||
__unhook 3 |
||
__value 2 |
||
naked 1 |
||
noinline 1 |
noreturn 1 |
|
nothrow 1 |
novtable 1 |
|
property 1 |
||
thread 1 |
||
uuid 1 |
||
1 __declspec 关键字的扩展特性。
2 仅适用于 C++ 托管扩展。 此语法现已弃用。
3 事件处理中使用的内部函数。
有关更多信息,请参见面向 CLR 的语言功能。
Microsoft 专用
在 Microsoft C++ 中,保留带有两条前导下划线的标识符以供编译器实现使用。 因此,Microsoft 约定位于带双下划线的 Microsoft 特定关键字前面。 这些单词不能用作标识符名称。
默认情况下将启用 Microsoft 扩展。 若要确保你的程序是完全可移植的,则可以通过在编译期间指定与 ANSI 兼容的 /Za 命令行选项(针对 ANSI 兼容性进行编译)来禁用 Microsoft 扩展。 如果这样做,将禁用 Microsoft 专用关键字。
启用 Microsoft 扩展后,你可以在程序中使用 Microsoft 特定关键字。 为了符合 ANSI,这些关键字的前面有一条双下划线。 出于向后兼容性考虑,支持除 __except、__finally、__leave 和 __try 以外的所有双下划线关键字的单下划线版本。 此外,还提供了没有前导下划线的 __cdecl。
__asm 关键字替代了 C++ asm 语法。 保留了 asm 以便与其他 C++ 实现兼容,但未成功。 请使用 __asm。
__based 关键字对于 32 位和 64 位目标编译的使用会受到限制。