名前空間
変種
操作

zero initialization

提供: cppreference.com
< cpp‎ | language

 
 
C + +言語
一般的なトピック
Original:
General topics
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
フロー制御
Original:
Flow control
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
条件付き実行文
Original:
Conditional execution statements
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
繰り返し文
Original:
Iteration statements
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
文をジャンプします
Original:
Jump statements
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
機能します
Original:
Functions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
関数の宣言
ラムダ関数の宣言
関数テンプレート
の歴史。インライン指定
例外仕様 (廃止予定)
noexcept指定子 (C++11)
例外
Original:
Exceptions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
名前空間
Original:
Namespaces
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
タイプ
Original:
Types
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
decltype specifier (C++11)
指定子
Original:
Specifiers
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
CV指定
貯蔵期間指定
constexprの指定子 (C++11)
自動指定 (C++11)
alignas指定子 (C++11)
初期化
Original:
Initialization
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
リテラル
Original:
Literals
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Original:
Expressions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
代替表現
ユーティリティ
Original:
Utilities
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
タイプ
Original:
Types
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
typedef declaration
型の別名宣言 (C++11)
属性 (C++11)
キャストします
Original:
Casts
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
暗黙の型変換
const_cast conversion
static_cast conversion
dynamic_cast conversion
reinterpret_cast conversion
Cスタイルキャストと機能
メモリの割り当て
Original:
Memory allocation
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
クラス
Original:
Classes
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
クラス固有の機能特性
Original:
Class-specific function properties
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
明示 (C++11)
静的
特殊なメンバ関数
Original:
Special member functions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
テンプレート
Original:
Templates
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
クラステンプレート
関数テンプレート
テンプレートの特殊化
パラメーターパック (C++11)
その他
Original:
Miscellaneous
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
インラインアセンブリ
 
ゼロにオブジェクトの初期値を設定します
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.

目次

[編集] 構文

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.
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.
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.
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.
ゼロ初期化の効果は、次のとおりです
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.
  • Tがスカラー型である場合、オブジェクトの初期値は暗黙的に変換されますに整数定数ゼロのTです.
    Original:
    If T is a scalar type, the object's initial value is the integral constant zero 暗黙的に変換されます to T.
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • Tは非組合クラス型である場合は、すべての基本クラスと非静的データメンバは、ゼロで初期化され、すべてのパディングがゼロ·ビットに初期化されます。コンストラクタは、もしあれば、無視される.
    Original:
    If T is 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:
    If T is 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:
    If T is array type, each element 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.
  • Tが参照型の場合、何も行われません.
    Original:
    If T is 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.
ゼロで初期化されたポインタがヌルポインタの値は、積分がゼロでない場合でも、その型のヌルポインタ値です.
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.

[編集]

#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
}


[編集] も参照してください