alignas specifier
来自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:
Specifies the alignment requirement of a type or an object.
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.
目录 |
[编辑] 语法
alignas( expression )
|
(C++11 起) | ||||||||
alignas( type-id )
|
(C++11 起) | ||||||||
[编辑] 解释
alignas说明变量或类的数据成员的声明,或者它可以被应用到一个类/结构/联合或枚举的定义.
Original:
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.
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.
alignas(expression)的形式,当使用expression是一个不可分割的常量表达式的计算结果为正值,声明的实体将有对齐要求设置的expression准确的结果,除非它会削弱类型的自然对齐要求的。
Original:
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.
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.
当使用的形式alignas(type),是完全等同于alignas(alignof(type)),也就是声明的实体的对齐要求,将是平等的对齐要求,type
Original:
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
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.
[编辑] 注释
alignas(0)有没有效果.
Original:
alignas(0) has no effect.
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.
当多个alignas说明适用于相同的变量或类的,最严格的人用了
Original:
When multiple alignas specifiers are applied to the same variable or class, the strictest one is used.
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.
C语言定义alignas作为一个宏在头<stdalign.h>,但在C + +中,这是一个关键字,并在头<stdalign.h>和<cstdalign>没有定义这样的宏。不必说什么,否则情况更糟,不过,他们定义宏不变__alignas_is_defined.
Original:
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.
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.
[编辑] 关键字
[编辑] 为例
// 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) |
获得该类型的对齐要求 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. (类模板) |