fork download
  1. #include <iostream>
  2.  
  3. struct Header {
  4. std::size_t datasize;
  5. int typecode;
  6. };
  7.  
  8. template <typename T>
  9. struct Payload {
  10. Header header;
  11. T offset[1];
  12.  
  13. void* data () {
  14. return &offset[0];
  15. }
  16. };
  17.  
  18. typedef unsigned char byte;
  19. const static auto null = nullptr;
  20.  
  21. int main () {
  22.  
  23. byte* data = new byte[sizeof(int) * 200 + sizeof(Header)];
  24. Payload<int>* payload = (Payload<int>*)data;
  25. int* properdatastart = (int*)payload->data();
  26.  
  27.  
  28. delete data;
  29. data = null;
  30. return 0;
  31. }
Success #stdin #stdout 0s 3024KB
stdin
Lol pointers
stdout
Standard output is empty