I want to know where to use alignof operator in c++14
#include <iostream>
struct Empty {};
struct Foo {
int f2;
float f1;
char c;
};
int main()
{
std::cout << "alignment of empty class: " << alignof(int*) << '\n';
std::cout << "sizeof of pointer : " << sizeof(Foo) <<"\n" ;
std::cout << "alignment of char : " << alignof(Foo) << '\n'
std::cout << "sizeof of Foo : " << sizeof(int*) << '\n' ;
}
I would like to know what alignof does in above program?
Some platforms either don't support reading misaligned data or are really slow at doing so. You can use
alignofwithalignasto create a char buffer suitable to storing other types thanchar(this is whatstd::aligned_storagedoes). For example...*taken from cppreference example