alignof operator (desde C++11)
De cppreference.com
<metanoindex/>
Consultas alinhamento requisitos de um tipo
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.
You can help to correct and verify the translation. Click here for instructions.
Sintaxe
alignof( type )
|
|||||||||
Retorna um objeto do tipo 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.
You can help to correct and verify the translation. Click here for instructions.
Explicação
Retorna o alinhamento em bytes (uma potência inteira de dois) necessário para qualquer instância do
type dado, que é um ou outro tipo completo, um tipo de matriz, ou um tipo de referência.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.
You can help to correct and verify the translation. Click here for instructions.
Se o tipo é tipo de referência, o operador retorna o alinhamento de referência tipo, se o tipo é tipo de matriz, exigência de alinhamento do tipo de elemento é retornado.
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.
You can help to correct and verify the translation. Click here for instructions.
Os tipos
char, signed char e unsigned char ter mais fraco alinhamento (menor) suportado pela implementação.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.
You can help to correct and verify the translation. Click here for instructions.
Palavras-chave
Exemplo
#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' ;
}
Saída:
alignment of empty class: 1
alignment of pointer : 8
alignment of char : 1
alignment of Foo : 4
