Storage duration
Storage duration,顾名思义,存储空间本身的持续时间。它应当不小于其所包含对象的生存周期(object lifetime)。
标准原文
和 C99,C++03比,新标准增加了一个thread相关的storage duration。
- C++ 标准(C++0x 3.7)
Storage duration is the property of an object that defines the minimum potential lifetime of the storage containing the object. The storage duration is determined by the construct used to create the object and is one of the following: — static storage duration — thread storage duration — automatic storage duration — dynamic storage duration
- C 标准(C1X 6.2.4)
An object has a storage duration that determines its lifetime. There are four storage durations: static, thread, automatic, and allocated.
分类
C++ 中的表述
哪些变量拥有 |
|
static |
1. 非thread、非dynamic所有的非局部变量 |
thread |
thread_local 声明的所有变量 |
automatic |
显式声明为register或非显式声明为static或extern的块作用域变量 |
dynamic |
程序执行中使用new表达式创建和delete表达式销毁的对象 |
C 中的表述
哪些变量拥有 |
|
static |
1. 未使用存储类别说明符_Thread_local且具有内部或外部链接性的对象 |
thread |
使用 _Thread_local 声明的对象 |
automatic |
声明为 no linkage 且没有使用存储类别说明符 static 的对象 |
allocated |
使用 aligned_alloc, calloc, malloc, realloc 分配 |
Storage class specifiers
C、C++ 分类上、术语上都有所不同。
C++
存储类别说明符:
- register
- static
- thread_local
- extern
- mutable
以下被称为类型说明符(Type specifiers)
- const
- volatile
- auto
- ...
C
存储类别说明符
- typedef
- extern
- static
-
_Thread_local
- auto
- register
注:typedef归于此类仅是出于语法上的便利。
而以下四个称为类型限定符(Type qualifiers)
- const
- restrict
- volatile
- _Atomic