fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. #include <windows.h>
  5.  
  6. #define T int
  7. typedef struct FakeVector FakeVector;
  8. struct FakeVector
  9. {
  10. T *mem;
  11. size_t capacity;
  12. size_t count;
  13. };
  14.  
  15. #define CHECK_ADD 1
  16.  
  17. void Add(FakeVector *vec, T *item)
  18. {
  19. while (1)
  20. {
  21. #if CHECK_MULTIPLY
  22. // This...
  23. if (vec->capacity > vec->capacity * 2)
  24. abort();
  25. // ...generates:
  26. // 0x00401504 mov 0x8(%rcx),%rdx
  27. // 0x00401508 lea (%rdx,%rdx,1),%rax
  28. // 0x0040150C cmp %rdx,%rax
  29. // 0x0040150F jae 0x401516 <Add+22>
  30. // 0x00401511 callq 0x4075d0 <abort>
  31. // 0x00401516 test %rdx,%rdx
  32. // 0x00401519 mov $0x10,%edx
  33. // 0x0040151E cmove %rdx,%rax
  34. // 0x00401522 incq 0x10(%rcx)
  35. // 0x00401526 mov %rax,0x8(%rcx)
  36. vec->capacity = vec->capacity
  37. ? (vec->capacity * 2)
  38. : 16;
  39. ++vec->count;
  40.  
  41. #elif CHECK_ADD
  42.  
  43. //if (vec->capacity + 1 < vec->capacity)
  44. if (vec->capacity > vec->capacity + 1)
  45. abort();
  46.  
  47. // 0x00401504 mov 0x8(%rcx),%rdx
  48. // 0x00401508 lea 0x1(%rdx),%rax
  49. // 0x0040150C cmp %rdx,%rax
  50. // 0x0040150F jae 0x401516 <Add+22>
  51. // 0x00401511 callq 0x4075d0 <abort>
  52. // 0x00401516 test %rdx,%rdx
  53. // 0x00401519 mov $0x10,%edx
  54. // 0x0040151E cmove %rdx,%rax
  55. // 0x00401522 mov %rax,0x8(%rcx)
  56.  
  57. vec->capacity = vec->capacity
  58. ? (vec->capacity + 1)
  59. : 16;
  60. #endif
  61. }
  62. }
  63.  
  64. //volatile int trick;
  65.  
  66. int main()
  67. {
  68. DebugBreak();
  69. FakeVector *vec;
  70. vec = (FakeVector*)calloc(1, sizeof(*vec));
  71. T val;
  72. while (1)
  73. Add(vec, &val);
  74. return 0;
  75. }
  76.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:4:21: fatal error: windows.h: No such file or directory
compilation terminated.
stdout
Standard output is empty