Bounds Checking in debug mode

D

DT

I don't know why C++ compilers (e.g. g++) don't include array bounds
checking in the debug mode or have a bounds-check flag.

May someone enlighten me?
 
S

Sousuke

I don't know why C++ compilers (e.g. g++) don't include array bounds
checking in the debug mode or have a bounds-check flag.

May someone enlighten me?

Are you sure g++ doesn't have such a flag? I think I once saw
something like that while skimming through the man page.

VC++ has something like that too, and it's enabled by default,
although it only works for arrays of one- or two-byte data types:

http://blogs.msdn.com/vcblog/archive/2009/03/19/gs.aspx
 
J

James Kanze

Specify -D_GLIBCXX_DEBUG with g++ and you'll get boundary, iterator
and many other checks to all STL containers and algorithms.
As for array boundary checks, that's technically very
difficult to do.

It's not that difficult to do per se. It's almost impossible to
do, however, while still maintaining compatibility with the
API's of the various libraries you might be using (or even the
system API).

IIRC, Centerline once had; the product is, apparently, still
available (see http://www.ics.com/products/centerline/).
Try running the program with valgrind.

Valgrind doesn't do true bounds checking; it's sufficient that
the memory being accessed has been correctly allocated. Thus:

int a[3][3];
a[0][4] = 42;

will not be caught by Valgrind, but should be by real bounds
checking.
 
I

Ian Collins

It's not that difficult to do per se. It's almost impossible to
do, however, while still maintaining compatibility with the
API's of the various libraries you might be using (or even the
system API).

IIRC, Centerline once had; the product is, apparently, still
available (see http://www.ics.com/products/centerline/).

If you happen to be developing on obsolete platforms!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,817
Latest member
AdalbertoT

Latest Threads

Top