_Alignas

From cppreference.com
< c‎ | language

Sets the alignment requirement of the declared object or member to the specified alignment.

Contents

[edit] Syntax

_Alignas( type-name ) (since C11)
_Alignas( constant-expression ) (since C11)

[edit] Explanation

Alignment is the requirement that objects of a particular type be located on storage boundaries with addresses that are particular multiples of a byte address.

Complete object types have alignment requirements which place restrictions on the addresses at which objects of that type may be allocated. An alignment is an implementation-defined integer value representing the number of bytes between successive addresses at which a given object can be allocated. An object type imposes an alignment requirement on every object of that type.

Alignments have an order from weaker to stronger, or stricter, alignments. Stricter alignments have larger alignment values. Stricter alignments can be requested using the _Alignas keyword.

Alignments are represented as values of the type size_t.

[edit] Keywords

_Alignas

[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);
}

Possible output:

0x6009c0
0x6009b0
0x6009b1