alignas specifier
来自cppreference.com
该页由英文版wiki使用Google Translate机器翻译而来。
该翻译可能存在错误或用词不当。鼠标停留在文本上可以看到原版本。你可以帮助我们修正错误或改进翻译。参见说明请点击这里. |
指定的种类或对象的对齐要求,.
原文:
Specifies the alignment requirement of a type or an object.
目录 |
[编辑] 语法
alignas( expression )
|
(C++11 起) | ||||||||
alignas( type-id )
|
(C++11 起) | ||||||||
[编辑] 解释
alignas说明变量或类的数据成员的声明,或者它可以被应用到一个类/结构/联合或枚举的定义.
原文:
The alignas specifier may be applied to the declaration of a variable or a class data member, or it can be applied to the definition of a class/struct/union or enum.
alignas(expression)的形式,当使用expression是一个不可分割的常量表达式的计算结果为正值,声明的实体将有对齐要求设置的expression准确的结果,除非它会削弱类型的自然对齐要求的。
原文:
When used in form alignas(expression), and expression is an integral constant expression that evaluates to a positive value, the declared entity will have its alignment requirement set to exactly the result of the expression, except if it would weaken the natural alignment requirement of the type.
当使用的形式alignas(type),是完全等同于alignas(alignof(type)),也就是声明的实体的对齐要求,将是平等的对齐要求,type
原文:
When used in form alignas(type), is exactly equivalent to alignas(alignof(type)), that is, the alignment requirement of the declared entity will be equal the alignment requirement of type
[编辑] 注释
alignas(0)有没有效果.
当多个alignas说明适用于相同的变量或类的,最严格的人用了
原文:
When multiple alignas specifiers are applied to the same variable or class, the strictest one is used.
C语言定义alignas作为一个宏在头<stdalign.h>,但在C + +中,这是一个关键字,并在头<stdalign.h>和<cstdalign>没有定义这样的宏。不必说什么,否则情况更糟,不过,他们定义宏不变__alignas_is_defined.
原文:
The C language defines alignas as a preprocessor macro in the header <stdalign.h>, but in C++ this is a keyword, and the headers <stdalign.h> and <cstdalign> do not define such macro. They do, however, define the macro constant __alignas_is_defined.
[编辑] 关键字
[编辑] 示例
// every object of type sse_t will be aligned to 16-byte boundary struct alignas(16) sse_t { float sse_data[4]; }; // the array "cacheline" will be aligned to 128-byte boundary char alignas(128) cacheline[128];
[编辑] 另请参阅
alignof operator | queries alignment requirements of a type (C++11 起) |
(C++11) |
获取类型的最小对齐字节数 (类模板) |