negativeDelta's blog

By negativeDelta, history, 14 months ago, In English

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

  • Vote: I like it
  • -9
  • Vote: I do not like it

| Write comment?
»
14 months ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

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.