Are _attribute((aligned(x))) and C++11 alignas the same?
1 Like
- It’s not an error to use
__attribute__((__aligned__(n)))ifn < alignof(T), but is foralignas(n)(“The combined effect of all alignment-specifiers in a declaration shall not specify an alignment that is less strict than the alignment that would be required for the entity being declared if all alignment-specifiers appertaining to that entity were omitted.” is the text from the C++17 spec). Note that GCC does not currently enforce this, but Clang does (65685 – Reducing alignment with alignas should be rejected). - You can write
alignas(T)as an alias foralignas(alignof(T)), but no equivalent__attribute__((__aligned__(T)))alias exists.
Those are the two I know of, there may be more subtle differences, including where the two can be placed.
1 Like
Thanks for your reply!