C++11 新特性alignof alignas std::aligned_storage std::align
alignment
#define CHECK_ALIGN(ptr, alignment) \
do{ \
constexpr size_t status \
= reinterpret_cast<uintptr_t>(ptr) % alignment; \
static_assert(status == 0, "ptr must be aligned"); \
}while(0) \alignof
#include <iostream>
int main()
{
char a;
int b;
long c;
std::cout << "alignof(char) " << alignof(a) << " alignof(int) "
<< alignof(b) << " alignof(long) " << alignof(c) << std::endl;
return 0;
}
g++ x.cpp -std=c++11
alignof(char) 1 alignof(int) 4 alignof(long) 8alignas
std::aligned_storage
std::align
最后更新于