Type alignment control

From cppreference.com
< c‎ | types

The C programming language, as of C11, supports type alignment with the built-in alignment specifier _Alignas and operator _Alignof (see _Alignas and _Alignof). When the header <stdalign.h> is included, the built-in alignment specifier and operator are also accessible as alignas and alignof.

[edit] Macros

Macro name Expands to
alignas _Alignas
alignof _Alignof
__alignas_is_defined integer constant 1
__alignof_is_defined integer constant 1

[edit] Example

#include <stdio.h>
#include <stdalign.h>
 
_Alignas(16) char a,b;
char c;
 
int main(void)
{
    printf("%p\n", (void*)&a);
    printf("%p\n", (void*)&b);
    printf("%p\n", (void*)&c);
 
    printf("_Alignof(float[10]) = %zu\n", _Alignof(float[10]));
}

Possible output:

0x6009f0
0x6009e0
0x6009e1
_Alignof(float[10]) = 4

[edit] See also

C++ documentation for Standard library header <cstdalign>