GCC STL bound checking
Asked Answered
M

2

47

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

Magnitogorsk answered 8/4, 2011 at 11:55 Comment(0)
D
76

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()

Dirac answered 8/4, 2011 at 11:59 Comment(2)
Note that using Debug Mode changes ABI, so you can't mix modules compiled with and without -DGLIBCXX_DEBUG.Outoftheway
@Outoftheway The correct symbol name is _GLIBCXX_DEBUG.Ladida
F
1

you should overload the operator[] for your specific classes. If you want to use an existing STL container, the at() function is a bounds-checked version of the operator[].

Furniture answered 8/4, 2011 at 12:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.