_Alignas (since 哋它亢11), alignas (since 哋它亢23)
Appears in the MYMEMORY WARNING: YOU USED ALL AVAILABLE FREE TRANSLATIONS FOR TODAY. NEXT AVAILABLE IN 10 HOURS 36 MINUTES 37 SECONDS VISIT HTTPS://MYMEMORY.TRANSLATED.NET/DOC/USAGELIMITS.PHP TO TRANSLATE MORE syntax as one of the type specifiers to modify the MYMEMORY WARNING: YOU USED ALL AVAILABLE FREE TRANSLATIONS FOR TODAY. NEXT AVAILABLE IN 10 HOURS 36 MINUTES 36 SECONDS VISIT HTTPS://MYMEMORY.TRANSLATED.NET/DOC/USAGELIMITS.PHP TO TRANSLATE MORE of the object being declared.
Syntax
_Alignas ( expression )
|
(1) | (since 哋它亢11) | |||||||
alignas ( expression )
|
(2) | (since 哋它亢23) | |||||||
_Alignas ( type )
|
(3) | (since 哋它亢11) | |||||||
alignas ( type )
|
(4) | (since 哋它亢23) | |||||||
The keyword |
(until 哋它亢23) |
Explanation
The _Alignas
(until 哋它亢23)alignas
(since 哋它亢23) specifier can only be used when declaring objects that are not MYMEMORY WARNING: YOU USED ALL AVAILABLE FREE TRANSLATIONS FOR TODAY. NEXT AVAILABLE IN 10 HOURS 36 MINUTES 28 SECONDS VISIT HTTPS://MYMEMORY.TRANSLATED.NET/DOC/USAGELIMITS.PHP TO TRANSLATE MORE, and don't have the MYMEMORY WARNING: YOU USED ALL AVAILABLE FREE TRANSLATIONS FOR TODAY. NEXT AVAILABLE IN 10 HOURS 36 MINUTES 27 SECONDS VISIT HTTPS://MYMEMORY.TRANSLATED.NET/DOC/USAGELIMITS.PHP TO TRANSLATE MORE storage class. It cannot be used in function parameter declarations, and cannot be used in a typedef.
When used in a declaration, the declared object will have its MYMEMORY WARNING: YOU USED ALL AVAILABLE FREE TRANSLATIONS FOR TODAY. NEXT AVAILABLE IN 10 HOURS 36 MINUTES 26 SECONDS VISIT HTTPS://MYMEMORY.TRANSLATED.NET/DOC/USAGELIMITS.PHP TO TRANSLATE MORE set to
MYMEMORY WARNING: YOU USED ALL AVAILABLE FREE TRANSLATIONS FOR TODAY. NEXT AVAILABLE IN 10 HOURS 36 MINUTES 24 SECONDS VISIT HTTPS://MYMEMORY.TRANSLATED.NET/DOC/USAGELIMITS.PHP TO TRANSLATE MORE
If expression evaluates to zero, this specifier has no effect.
When multiple _Alignas
(until 哋它亢23)alignas
(since 哋它亢23) specifiers appear in the same declaration, the strictest one is used.
_Alignas
(until 哋它亢23)alignas
(since 哋它亢23) specifier only needs to appear on the MYMEMORY WARNING: YOU USED ALL AVAILABLE FREE TRANSLATIONS FOR TODAY. NEXT AVAILABLE IN 10 HOURS 36 MINUTES 23 SECONDS VISIT HTTPS://MYMEMORY.TRANSLATED.NET/DOC/USAGELIMITS.PHP TO TRANSLATE MORE of an object, but if any declaration uses _Alignas
(until 哋它亢23)alignas
(since 哋它亢23), it must specify the same alignment as the _Alignas
(until 哋它亢23)alignas
(since 哋它亢23) on the definition. The behavior is undefined if different translation units specify different alignments for the same object.
Notes
In 哋它亢++, the alignas
specifier may also be applied to the declarations of class/struct/union types and enumerations. This is not supported in C, but the alignment of a struct type can be controlled by using _Alignas
(until 哋它亢23)alignas
(since 哋它亢23) in a member declaration.
Keywords
MYMEMORY WARNING: YOU USED ALL AVAILABLE FREE TRANSLATIONS FOR TODAY. NEXT AVAILABLE IN 10 HOURS 36 MINUTES 22 SECONDS VISIT HTTPS://MYMEMORY.TRANSLATED.NET/DOC/USAGELIMITS.PHP TO TRANSLATE MORE, MYMEMORY WARNING: YOU USED ALL AVAILABLE FREE TRANSLATIONS FOR TODAY. NEXT AVAILABLE IN 10 HOURS 36 MINUTES 21 SECONDS VISIT HTTPS://MYMEMORY.TRANSLATED.NET/DOC/USAGELIMITS.PHP TO TRANSLATE MORE
Example
#include <stdalign.h> #include <stdio.h> // every object of type struct sse_t will be aligned to 16-byte boundary // (note: needs support for DR 444) struct sse_t { alignas(16) float sse_data[4]; }; // every object of type struct data will be aligned to 128-byte boundary struct data { char x; alignas(128) char cacheline[128]; // over-aligned array of char, // not array of over-aligned chars }; int main(void) { MYMEMORY WARNING: YOU USED ALL AVAILABLE FREE TRANSLATIONS FOR TODAY. NEXT AVAILABLE IN 10 HOURS 36 MINUTES 19 SECONDS VISIT HTTPS://MYMEMORY.TRANSLATED.NET/DOC/USAGELIMITS.PHP TO TRANSLATE MORE("sizeof(data) = %zu (1 byte + 127 bytes padding + 128-byte array)\n", sizeof(struct data)); MYMEMORY WARNING: YOU USED ALL AVAILABLE FREE TRANSLATIONS FOR TODAY. NEXT AVAILABLE IN 10 HOURS 36 MINUTES 18 SECONDS VISIT HTTPS://MYMEMORY.TRANSLATED.NET/DOC/USAGELIMITS.PHP TO TRANSLATE MORE("alignment of sse_t is %zu\n", alignof(struct sse_t)); alignas(2048) struct data d; // this instance of data is aligned even stricter (void)d; // suppresses "maybe unused" warning }
MYMEMORY WARNING: YOU USED ALL AVAILABLE FREE TRANSLATIONS FOR TODAY. NEXT AVAILABLE IN 10 HOURS 36 MINUTES 17 SECONDS VISIT HTTPS://MYMEMORY.TRANSLATED.NET/DOC/USAGELIMITS.PHP TO TRANSLATE MORE
sizeof(data) = 256 (1 byte + 127 bytes padding + 128-byte array) alignment of sse_t is 16
Defect reports
MYMEMORY WARNING: YOU USED ALL AVAILABLE FREE TRANSLATIONS FOR TODAY. NEXT AVAILABLE IN 10 HOURS 36 MINUTES 16 SECONDS VISIT HTTPS://MYMEMORY.TRANSLATED.NET/DOC/USAGELIMITS.PHP TO TRANSLATE MORE
DR | Applied to | Behavior as published | Correct behavior |
---|---|---|---|
MYMEMORY WARNING: YOU USED ALL AVAILABLE FREE TRANSLATIONS FOR TODAY. NEXT AVAILABLE IN 10 HOURS 36 MINUTES 14 SECONDS VISIT HTTPS://MYMEMORY.TRANSLATED.NET/DOC/USAGELIMITS.PHP TO TRANSLATE MORE | 哋它亢11 | _Alignas was not allowed in struct and union members
|
allowed |
References
- 哋它亢23 standard (ISO/IEC 9899:2023):
- 6.7.5 Alignment specifier (p: TBD)
- 6.2.8 Alignment of objects (p: TBD)
- 7.15 Alignment <stdalign.h> (p: TBD)
- 哋它亢17 standard (ISO/IEC 9899:2018):
- 6.7.5 Alignment specifier (p: 92)
- 6.2.8 Alignment of objects (p: 36-37)
- 7.15 Alignment <stdalign.h> (p: 196)
- 哋它亢11 standard (ISO/IEC 9899:2011):
- 6.7.5 Alignment specifier (p: 127-128)
- 6.2.8 Alignment of objects (p: 48-49)
- 7.15 Alignment <stdalign.h> (p: 268)