Storage-class specifiers
来自cppreference.com
该页由英文版wiki使用Google Translate机器翻译而来。
该翻译可能存在错误或用词不当。鼠标停留在文本上可以看到原版本。你可以帮助我们修正错误或改进翻译。参见说明请点击这里. |
auto
- 自动持续时间没有联系.原文:auto
- automatic duration with no linkage.register
- 自动持续时间没有联系。也暗示编译器将处理器的寄存器中的变量.原文:register
- automatic duration with no linkage. Also hints to the compiler to place the variable in the processor's register.static
- 静态持续时间的内部联动.原文:static
- static duration with internal linkage.extern
- 静态持续时间的内部或更通常是外部的联动.原文:extern
- static duration with either internal or more usually external linkage._Thread_local
- (C11 起) - 的线程存储时间.原文:_Thread_local
- (C11 起) - thread storage duration.
目录 |
[编辑] 解释
[编辑] 储存时间
在一个程序中的所有变量有以下存储的持续时间决定了它的寿命
原文:
All variables in a program have one of the following storage durations that determines its lifetime:
- 自动'的存储时间。该变量被分配在封闭的代码块的开头和结束时将释放。这是默认情况下,所有的变量,申报者外
static
,extern
或_Thread_local
.原文:automatic storage duration. The variable is allocated at the beginning of the enclosing code block and deallocated at the end. This is the default for all variables, except those declaredstatic
,extern
or_Thread_local
.
- '“静态”的存储时间。变量在程序开始时分配和释放程序结束时。只有一个实例变量的存在。声明的变量
static
或extern
有此存储时间.原文:static storage duration. The variable is allocated when the program begins and deallocated when the program ends. Only one instance of the variable can exist. Variables declared withstatic
orextern
have this storage duration.
- “”线“”的存储时间(C11 起)。变量线程开始时分配和释放的线程结束时。每个线程都有它自己的实例的变量。只有声明的变量
_Thread_local
有这样的存储时间。_Thread_local
声明的变量只能被声明为static
或extern
,不能用在函数声明中.....原文:thread storage duration (C11 起). The variable is allocated when the thread begins and deallocated when the thread ends. Each thread has its own instance of the variable. Only variables declared_Thread_local
have this storage duration._Thread_local
can only be declared for variables declared withstatic
orextern
and cannot be used in a function declaration.
[编辑] 联动
连接是指一个变量或函数被称为在其他范围内的能力。如果具有相同标识符的变量或函数的声明在几个范围,但不能被称为从所有这些,那么所产生的几个实例变量。以下联系确认
原文:
Linkage refers to the ability of a variable or function to be referred to in other scopes. If a variable or function with the same identifier is declared in several scopes, but cannot be referred to from all of them, then several instances of the variable are generated. The following linkages are recognized:
- 没有任何联系“。”可以被称为变量的范围是自动,线程和动态存储时间长。所有的变量,这种联系.....原文:no linkage. The variable can be referred to only from the scope it is in. All variables with automatic, thread and dynamic storage durations have this linkage.
- 内部联动。变量可以被称为当前转换单元中的所有范围。所有的变量所宣派
static
有这种联系.原文:internal linkage. The variable can be referred to from all scopes in the current translation unit. All variables which are declaredstatic
have this linkage.
- 外部链接。变量可以被称为整个程序中的任何其他翻译单位。所有变量声明为
extern
或const
没有明确的存储类说明符,但不static
,这种联系.....原文:external linkage. The variable can be referred to from any other translation units in the entire program. All variables which are declared eitherextern
orconst
with no explicit storage-class specifier, but notstatic
, have this linkage.
[编辑] 关键字
auto, register, static, extern, _Thread_local
[编辑] 示例
本章尚未完成 |