fork(19) download
  1. #include <stdio.h>
  2.  
  3. // tested on gcc-4.9.3 on linux gentoo amd64
  4. // warning: compiling this will eat gigabytes of ram really fast so keep
  5. // your CTRL-C ready
  6. // compile with --std=c++14
  7.  
  8. struct v2f {
  9. float x=0, y=0; // must be =0 to reproduce (probably works with other vals)
  10. };
  11.  
  12. namespace {
  13. struct foo {
  14. // declaring the array like this somehow bypasses the fact that
  15. // v2f cannot be initialized with {0}
  16. static const size_t max_objects = 0xFFFF;
  17. size_t num_objects; // this is not necessary, just wanted to check if it still did it when not accessing bars
  18. v2f bars[max_objects * 255]; // the larger this array is, the longer it hangs for and the more memory it uses
  19. };
  20.  
  21. foo f{0}; // must be initialized with {0} to reproduce
  22. }
  23.  
  24. int main() {
  25. printf("%ld\n", f.num_objects);
  26. }
  27.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
virtual memory exhausted: Cannot allocate memory
stdout
Standard output is empty