Storage duration specifiers
来自cppreference.com
该页由英文版wiki使用Google Translate机器翻译而来。
该翻译可能存在错误或用词不当。鼠标停留在文本上可以看到原版本。你可以帮助我们修正错误或改进翻译。参见说明请点击这里. |
auto
- “自动”存储的时间。 (已弃用)原文:auto
- automatic storage duration. (已弃用)register
- “自动”存储的时间。也暗示编译器将处理器的寄存器中的变量。 (已弃用)原文:register
- automatic storage duration. Also hints to the compiler to place the variable in the processor's register. (已弃用)static
- “静态”的贮藏期和“内部”联动原文:static
- static storage duration and internal linkageextern
- “静态”的贮藏期和“外部”的联动原文:extern
- static storage duration and external linkagethread_local
- “话题”存储时间。 (C++11 起)原文:thread_local
- thread storage duration. (C++11 起)
目录 |
[编辑] 解释
[编辑] 储存时间
所有的变量在程序中有以下存储持续时间
原文:
All variables in a program have one of the following storage durations:
- 自动'的存储时间。在封闭的代码块的开头的变量被分配和释放就结束。所有非全局变量的存储期限,申报者外
static
,extern
或thread_local
.原文:automatic storage duration. The variable is allocated at the beginning of the enclosing code block and deallocated on end. All non-global variables have this storage duration, except those declaredstatic
,extern
orthread_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 exists. All global variables have this storage duration, plus those declared withstatic
orextern
.
- “”线“”的存储时间(C++11 起)。变量线程开始时分配和释放的线程结束时。每个线程都有它自己的实例的变量。只有声明的变量
thread_local
有这样的存储时间。thread_local
只能被声明为全局变量,再加上,那些与static
声明或extern
.原文:thread storage duration (C++11 起). 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 declaredthread_local
have this storage duration.thread_local
can only be declared for global variables, plus those declared withstatic
orextern
.
[编辑] 联动
连接是指一个变量或函数被称为在其他范围内的能力。如果具有相同标识符的变量或函数的声明在几个范围,但不能被称为从所有这些,那么所产生的几个实例变量。以下联系确认
原文:
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
,或const
,但不extern
,有这样的联系.原文:internal linkage. The variable can be referred to from all scopes in the current translation unit. All variables with static storage duration which are either declaredstatic
, orconst
but notextern
, have this linkage.
- 外部链接。变量可以被称为在其他的翻译单元的范围。所有的变量具有静态存储持续时间有这种联系,但不申报者外
static
,或const
extern
.原文:external linkage. The variable can be referred to from the scopes in the other translation units. All variables with static storage duration have this linkage, except those declaredstatic
, orconst
but notextern
.
[编辑] 关键字
auto, register, static, extern, thread_local
[编辑] 示例
本章尚未完成 |