fork(2) download
  1. #include <iostream>
  2. #include <type_traits>
  3.  
  4.  
  5. constexpr int Alignment = 256;
  6. struct alignas(Alignment)AlignedStruct {
  7. int dummy;
  8. };
  9. using AlignedStorage = typename std::aligned_storage<sizeof(AlignedStruct), alignof(AlignedStruct)>::type;
  10. using AlignedUnion = typename std::aligned_union<1, AlignedStruct>::type;
  11. using Aligned256 = typename std::aligned_storage<256, 256>::type;
  12.  
  13. template<typename X>
  14. void print()
  15. {
  16. std::cout << "size=" << sizeof(X) << ", align=" << alignof(X) << "." << std::endl;
  17. }
  18.  
  19. int main(void)
  20. {
  21. print<AlignedStruct>();
  22. print<AlignedStorage>();
  23. print<AlignedUnion>();
  24. print<Aligned256>();
  25. return 0;
  26. }
  27.  
Success #stdin #stdout 0s 3456KB
stdin
Standard input is empty
stdout
size=4, align=4.
size=4, align=4.
size=4, align=4.
size=256, align=256.