◐ Shell
clean mode source ↗

zero initialization – cppreference.com

Aus cppreference.com

<metanoindex/>

Stellt die anfängliche Wert eines Objekts auf Null

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.

Syntax

static T object ; (1)
int () ; (2)
char array [ n ] = ""; (3)

Erklärung

Zero-Initialisierung in den folgenden Situationen ausgeführt:

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)

Für jeden benannten Variablen mit statischen oder thread-lokalen Speicher Dauer, vor allen anderen die Initialisierung .

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)

Als Teil der Value-Initialisierung Sequenz für Nicht-Klasse-Typen und für die Mitglieder der Wert initialisiert Klasse-Typen, die keine Konstruktoren haben .

Original:

As part of Value-Initialisierung 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)

Wenn ein Charakter-Array mit einem String-Literal, die zu kurz ist initialisiert wird, ist der Rest des Feldes Null initialisiert .

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.

Die Auswirkungen von Null Initialisierung sind:

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.

  • Wenn T eine skalare Typ ist, ist das Objekt Anfangswert der integrale Konstante Null implizit konvertiert um T .

    Original:

    If T is a scalar type, the object's initial value is the integral constant zero implizit konvertiert to T.

    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.

  • Wenn T ein nicht-union-Klasse Typ ist, sind alle Basisklassen und nicht-statische Datenelemente Null initialisiert, und alle padding auf Null Bits initialisiert. Die Konstruktoren, wenn überhaupt, werden ignoriert .

    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.

  • Wenn T eine Vereinigung Typ ist, ist der erste nicht-statische Element Namendaten Null initialisiert wird und alle Polster wird auf Null initialisiert Bits .

    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.

  • Wenn T Array-Typ ist, ist jedes Element Null initialisiert

    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.

  • Wenn T Referenz-Typ ist, wird nichts getan .

    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.

Notes

Die statischen und thread-lokale Variablen sind erste Null initialisiert und dann wieder wie im Programm angegeben initialisiert, z. B. eine Funktion-local statisch ist erste Null initialisiert beim Programmstart und dann den Konstruktor wird aufgerufen, wenn die Funktion zuerst eingegeben wird. Wird die Erklärung eines nicht-static hat keine Initialisierung, dann Default-Initialisierung tut nichts, so dass das Ergebnis der früheren Null-Initialisierung unverändert .

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.

Eine Null initialisiert Zeiger ist der Null-Zeiger-Wert seiner Art, auch wenn der Wert des Zeigers Null ist kein wesentlicher Null .

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.

Beispiel

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

Siehe auch