Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GCC STL bound checking

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

like image 600
pic11 Avatar asked Apr 08 '11 11:04

pic11


2 Answers

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

like image 124
Peter G. Avatar answered Sep 28 '22 05:09

Peter G.


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[].

like image 38
Tony The Lion Avatar answered Sep 28 '22 05:09

Tony The Lion