alignof operator (начиная с C++11)
Материал из 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:
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.
Содержание |
[править] Синтаксис
alignof( type )
|
|||||||||
Возвращает объект типа 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.
[править] Объяснение
Возвращает выравнивание в байтах (целое число степенью двойки), необходимых для любого экземпляра данного
type, который является либо полное тип, тип массива, или ссылки типа.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.
Если тип является ссылочным типом, оператор возвращает выравнивание' ссылочного типа, если тип является типом массива, выравнивание требование тип элемента возвращается.
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.
Типы char, signed char, и unsigned char имеют слабое (маленький) выравнивание поддерживается реализацией.
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.
[править] Ключевые слова
[править] Пример
#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' ; }
Вывод:
alignment of empty class: 1 alignment of pointer : 8 alignment of char : 1 alignment of Foo : 4
[править] См. также
| alignas спецификатор | указывает, что для хранения переменной должны быть согласованы конкретные (C++11) сумму
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. |
| (C++11) |
получает выравнивания типа требований 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. (шаблон класса) |