fork download
  1. #include <atomic>
  2. #include <utility>
  3. #include <new>
  4. #include <iostream>
  5.  
  6. using namespace std;
  7.  
  8. struct MyStruct
  9. {
  10. char m_value = 10;
  11. } __attribute__ ((aligned (16)));
  12.  
  13. template <class T>
  14. struct Item
  15. {
  16. std::atomic< Item* > m_next;
  17. char m_data[ sizeof( T ) ];
  18. };
  19.  
  20. int main()
  21. {
  22. cout << "MyStruct: " << alignof(MyStruct) << endl;
  23. cout << "Item: " << alignof(Item<MyStruct>) << endl;
  24. Item<MyStruct> items[4];
  25. for (int i = 0; i < 4; ++i)
  26. {
  27. MyStruct* value = new (items[i].m_data) MyStruct();
  28. if (((size_t)value & 0x7) != 0)
  29. cout << "Такого не бывает" << endl;
  30. if (((size_t)value & 0xF) != 0)
  31. cout << "Сосем хуйцы" << endl;
  32. }
  33. return 0;
  34. }
  35.  
Success #stdin #stdout 0s 4456KB
stdin
Standard input is empty
stdout
MyStruct: 16
Item:     8
Сосем хуйцы
Сосем хуйцы