Bounds Checking in debug mode

Discussion in 'C++' started by DT, Mar 9, 2010.

  1. DT

    DT Guest

    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?
    DT, Mar 9, 2010
    #1
    1. Advertising

  2. DT

    Sousuke Guest

    On Mar 9, 1:02 am, DT <> wrote:
    > 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
    Sousuke, Mar 9, 2010
    #2
    1. Advertising

  3. DT

    James Kanze Guest

    On Mar 9, 11:46 pm, Juha Nieminen <> wrote:
    > 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.

    --
    James Kanze
    James Kanze, Mar 11, 2010
    #3
  4. DT

    Ian Collins Guest

    On 03/12/10 12:19 PM, James Kanze wrote:
    > On Mar 9, 11:46 pm, Juha Nieminen<> wrote:
    >> 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/).


    If you happen to be developing on obsolete platforms!

    --
    Ian Collins
    Ian Collins, Mar 11, 2010
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Casey Hawthorne
    Replies:
    21
    Views:
    860
    Roedy Green
    Jun 5, 2004
  2. Chris

    Array bounds checking

    Chris, Jul 5, 2005, in forum: Java
    Replies:
    5
    Views:
    771
  3. Casey Hawthorne
    Replies:
    16
    Views:
    1,194
  4. Jim Cook

    Macro argument bounds checking?

    Jim Cook, Sep 17, 2003, in forum: C Programming
    Replies:
    7
    Views:
    810
    Dave Thompson
    Sep 22, 2003
  5. Julian Zhang

    Bounds Checking?

    Julian Zhang, Jan 12, 2004, in forum: C Programming
    Replies:
    3
    Views:
    588
    E. Robert Tisdale
    Jan 20, 2004
Loading...

Share This Page