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,这是无论是完整的类型,数组类型,或引用类型的实例所需的任何调整(以字节为单位)(2的整数次幂).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' ; }
Output:
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. (类模板) |