- 论坛徽章:
- 0
|
ISO C/C++没有.bss的概念。
C的文件作用域对象,C++的全局(命名空间作用域)变量具有静态存储期:
ISO C11(N1570)
6.2.4
3 An object whose identifier is declared without the storage-class specifier _Thread_local, and either with external or internal linkage or with the storage-class specifier static, has static storage duration. Its lifetime is the entire execution of the program and its stored value is initialized only once, prior to program startup.
ISO C++11
3.7.1 Static storage duration [basic.stc.static]
1 All variables which do not have dynamic storage duration, do not have thread storage duration, and are not local have static storage duration. The storage for these entities shall last for the duration of the program (3.6.2, 3.6.3).
如果没有显式初始化,则默认行为可以总结为填0(但关于实际的存储值则有些差别,例如null pointer不必然保证是0):
ISO C11(N1570) 6.7.9
10 If an object that has automatic storage duration is not initialized explicitly, its value is indeterminate. If an object that has static or thread storage duration is not initialized explicitly, then:
— if it has pointer type, it is initialized to a null pointer;
— if it has arithmetic type, it is initialized to (positive or unsigned) zero;
— if it is an aggregate, every member is initialized (recursively) according to these rules, and any padding is initialized to zero bits;
— if it is a union, the first named member is initialized (recursively) according to these rules, and any padding is initialized to zero bits;
关于ISO C++11见http://bbs.chinaunix.net/thread-3710317-4-1.html的40L。
|
|