fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. struct some_struct
  5. {
  6. double m;
  7. };
  8.  
  9. static_assert(sizeof(some_struct) == sizeof(std::int64_t));
  10. static_assert(alignof(some_struct) == alignof(std::int64_t));
  11.  
  12. char buf[] = {
  13. // some prefix
  14. 0x1, 0x2, 0x3,
  15. // now struct data
  16. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08
  17. };
  18.  
  19. int main() {
  20. some_struct* s = reinterpret_cast<some_struct*>(buf + 3);
  21. // now let's check alignment
  22. std::cout << reinterpret_cast<std::uintptr_t>(s) % alignof(some_struct);
  23. return 0;
  24. }
Success #stdin #stdout 0s 4504KB
stdin
Standard input is empty
stdout
3