You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The alignas type specifier is a portable, C++ standard way to specify custom alignment of variables and user defined types. The alignof operator is likewise a standard, portable way to obtain the alignment of a specified type or variable.
Example
You can use alignas on a class, struck or union, or on individual members. When multiple alignas specifiers are encountered, the compiler will choose the strictest one, (the one with the largest value).
// alignas_alignof.cpp// compile with: cl /EHsc alignas_alignof.cpp
#include<iostream>structalignas(16) Bar
{
int i; // 4 bytes int n; // 4 bytes alignas(4) char arr[3];
short s; // 2 bytes
};
intmain()
{
std::cout << alignof(Bar) << std::endl; // output: 16
}