zero initialization
来自cppreference.com
|
|
This page has been machine-translated from the English version of the wiki using Google Translate.
The translation may contain errors and awkward wording. Hover over text to see the original version. You can help to fix errors and improve the translation. For instructions click here. |
设置一个对象的初始值为零
Original:
Sets the initial value of an object to zero
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
目录 |
[编辑] 语法
static T object ;
|
(1) | ||||||||
int () ;
|
(2) | ||||||||
char array [ n ] = "";
|
(3) | ||||||||
[编辑] 解释
零初始化是在以下几种情况:
Original:
Zero initialization is performed in the following situations:
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
1)
对于每一个已命名的变量与静态或线程局部存储的持续时间,在任何其他初始化.
Original:
For every named variable with static or thread-local storage duration, before any other initialization.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
2)
作为值初始化非类类型和成员的值初始化有没有构造函数的类类型的序列.
Original:
As part of 值初始化 sequence for non-class types and for members of value-initialized class types that have no constructors.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
3)
当一个字符数组初始化一个字符串文字太短,其余是零初始化的数组.
Original:
When a character array is initialized with a string literal that is too short, the remainder of the array is zero-initialized.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
零初始化的效果是:
Original:
The effects of zero initialization are:
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
-
T是一个标量类型,对象的初始值是整型常量零隐式转换T.Original:The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
-
T是一个非工会的类类型,所有的基类和非静态数据成员是零初始化,初始化所有的填充零位。构造函数,如果有的话,被忽视Original:IfTis an non-union class type, all base classes and non-static data members are zero-initialized, and all padding is initialized to zero bits. The constructors, if any, are ignored.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
-
T是一个联合类型,第一个非静态的数据成员是零初始化,初始化所有的填充零位.Original:IfTis a union type, the first non-static named data member is zero-initialized and all padding is initialized to zero bits.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
-
T是数组类型,每个元素都是零初始化Original:IfTis array type, each element is zero-initializedThe text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
- 如果
T是引用类型,什么都不做.Original:IfTis reference type, nothing is done.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
[编辑] 注释
零初始化的静态和线程局部变量是第一,然后重新初始化程序中指定,例如:函数局部静态是第一个在程序启动时初始化为零的,那么它的构造函数被调用该函数时,第一次进入。如果一个类的静态声明没有初始化,那么默认的初始化什么也不做,把结果较早的零初始化未修改的.
Original:
The static and thread-local variables are first zero-initialized and then initialized again as specified in the program, e.g. a function-local static is first zero-initialized at program startup, and then its constructor is called when the function is first entered. If the declaration of a non-class static has no initializer, then default initialization does nothing, leaving the result of the earlier zero-initialization unmodified.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
初始化为零的指针是空指针值,即使它的类型的空指针的值不是整数零.
Original:
A zero-initialized pointer is the null pointer value of its type, even if the value of the null pointer is not integral zero.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
[编辑] 为例
#include <string> double f[3]; // zero-initialized to three 0.0's int* p; // zero-initialized to null pointer value std::string s; // zero-initialized to indeterminate value // then default-initialized to "" int main(int argc, char* argv[]) { static int n = argc; // zero-initialized to 0 // then copy-initialized to argc delete p; // safe to delete a null pointer }

