#include <iostream>
struct Foo
{
int i;
float f;
char c;
};
struct alignas(alignof(long double)) Foo2
{
};
struct Empty {};
struct alignas(64) Empty64 {};
int main()
{
std::cout << "Alignment of" "\n"
"- char : " << alignof(char) << "\n"
"- pointer : " << alignof(int*) << "\n"
"- class Foo : " << alignof(Foo) << "\n"
"- class Foo2 : " << alignof(Foo2) << "\n"
"- empty class : " << alignof(Empty) << "\n"
"- empty class\n"
" with alignas(64): " << alignof(Empty64) << "\n";
}
Alignment of
- char : 1
- pointer : 8
- class Foo : 4
- class Foo2 : 16
- empty class : 1
- empty class
with alignas(64): 64
출처: cppreference.com