Блог пользователя negativeDelta

Автор negativeDelta, история, 17 месяцев назад, По-английски

In case of vector<int> a(2), if I try to access a[2], I get runtime error. But in case of vector<long long> a(2), if I try to access a[2], there is no runtime error.
Why?

Runtime error solution: 203977137
Accepted solution: 203978634

  • Проголосовать: нравится
  • -9
  • Проголосовать: не нравится

»
17 месяцев назад, # |
Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

Because accessing an out of bounds index is Undefined Behavior. In my computer it does not show any error, and probably in another computer it shows error with int and long long. If you want to avoid this kind of bugs you can compile with GCC adding flag -D_GLIBCXX_DEBUG. Note that this does not show errors on C arrays.