GCC STL bound checking

pic11 picture pic11 · Apr 8, 2011 · Viewed 7.9k times · Source

How do I enable bound checking for operator[] and iterators?

Answer

Peter G. picture Peter G. · Apr 8, 2011

You can activate runtime iterator and bounds checking by compiling with -D_GLIBCXX_DEBUG. Also note that random-access containers provide the always bounds-checking at()-operation in addition to operator [].

References:

GCC STL debug mode: http://gcc.gnu.org/onlinedocs/libstdc++/manual/debug_mode_using.html#debug_mode.using.mode

at() operation: std::vector::at(), std::deque::at() and std::array::at()