◐ Shell
clean mode source ↗

alignof operator (seit C++11) – cppreference.com

Aus cppreference.com

<metanoindex/>

Abfragen Ausrichtungsanforderungen eines Typs

Original:

Queries alignment requirements of a type

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

Syntax

alignof( type )

Gibt ein Objekt vom Typ std::size_t .

Original:

Returns an object of type std::size_t.

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

Erklärung

Versandkosten Ausrichtung in Bytes (eine ganzzahlige Potenz von zwei) für jede Instanz des angegebenen type, die entweder komplett Typ, ein Array-Typ oder ein Referenztyp ist erforderlich .

Original:

Returns alignment in bytes (an integer power of two) required for any instance of the given type, which is either complete type, an array type, or a reference type.

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

Wenn der Typ Referenz-Typ, gibt der Operator die Ausrichtung der verwiesen Typ, wenn der Typ Array-Typ, Ausrichtung Forderung der Element-Typ zurückgegeben wird .

Original:

If the type is reference type, the operator returns the alignment of referenced type; if the type is array type, alignment requirement of the element type is returned.

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

Die Typen char, signed char und unsigned char die schwächste (kleinste) Ausrichtung durch die Implementierung unterstützt .

Original:

The types char, signed char, and unsigned char have the weakest (smallest) alignment supported by the implementation.

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

Keywords

alignof

Beispiel

#include <iostream>

struct Empty {};

struct Foo {
     int f2;
     float f1;
     char c;
};

int main()
{
    std::cout << "alignment of empty class: " << alignof(Empty) << '\n'
              << "alignment of pointer : "    << alignof(int*)  << '\n'
              << "alignment of char : "       << alignof(char)  << '\n'
              << "alignment of Foo : "        << alignof(Foo)   << '\n' ;
}

Output:

alignment of empty class: 1
alignment of pointer : 8
alignment of char : 1
alignment of Foo : 4

Siehe auch

alignas Spezifizierer

gibt an, dass der Speicher für die Variable durch bestimmte Menge (C++11) ausgerichtet werden soll

Original:

specifies that the storage for the variable should be aligned by specific amount (C++11)

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

[edit]

Ruft den Type der Alignment-Anforderungen

Original:

obtains the type's alignment requirements

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


(Klassen-Template) [edit]