alignof operator (C++11 起)
来自cppreference.com
该页由英文版wiki使用Google Translate机器翻译而来。
该翻译可能存在错误或用词不当。鼠标停留在文本上可以看到原版本。你可以帮助我们修正错误或改进翻译。参见说明请点击这里. |
查询的对齐要求的类型
原文:
Queries alignment requirements of a type
目录 |
[编辑] 语法
alignof( type )
|
|||||||||
返回对象类型std::size_t
原文:
Returns an object of type std::size_t.
[编辑] 解释
返回
type
,这是无论是完整的类型,数组类型,或引用类型的实例所需的任何调整(以字节为单位)(2的整数次幂).原文:
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.如果类型是引用类型,操作符返回的对齐方式“引用”类型,如果该类型是数组类型,元素类型的对齐要求,返回.
原文:
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.
类型char,signed char,unsigned char最弱(最小)对齐实现支持.
原文:
The types char, signed char, and unsigned char have the weakest (smallest) alignment supported by the implementation.
[编辑] 关键字
[编辑] 示例
#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)
原文: specifies that the storage for the variable should be aligned by specific amount (C++11) |
(C++11) |
获取类型的最小对齐字节数 (类模板) |