can assert() hide debug dump out?

Discussion in 'C++' started by John Black, Jul 8, 2004.

  1. John Black

    John Black Guest

    Hi,
    I am using assert() to hide some debug dump out like this,

    int dump(){
    ... some printf...
    return 0;
    }

    then in my main code, I do this,
    assert(dump() == 0);

    I wished using this way to avoid that dump() is called in optimized
    mode compile, but it seems it does not work! I still see the dump out in
    optimized version.

    Any idea?
     
    John Black, Jul 8, 2004
    #1
    1. Advertising

  2. John Black wrote:
    > I am using assert() to hide some debug dump out like this,
    >
    > int dump(){
    > ... some printf...
    > return 0;
    > }
    >
    > then in my main code, I do this,
    > assert(dump() == 0);
    >
    > I wished using this way to avoid that dump() is called in optimized
    > mode compile, but it seems it does not work! I still see the dump out in
    > optimized version.
    >
    > Any idea?


    Make sure your "optimized mode compile" defines NDEBUG macro.

    Victor
     
    Victor Bazarov, Jul 8, 2004
    #2
    1. Advertising

  3. John Black

    Phlip Guest

    John Black wrote:

    > assert(dump() == 0);
    >
    > I wished using this way to avoid that dump() is called in optimized
    > mode compile, but it seems it does not work! I still see the dump out in
    > optimized version.
    >
    > Any idea?


    assert() becomes nothing when NDEBUG is turned on. Look that up. It's a
    system different from your compiler's optimization settings. Many
    environments put all these details together into modes, such as Debug Mode
    and Release Mode. But they are all different systems.

    BTW if you put a whole bunch of assertions inside your dump(), and rename it
    test(), then you'd have an in-vivo test suite. Running these over and over
    again, and putting all conceivable requirements inside them, is a great way
    to keep bugs out, and prevent the need to Debug.

    --
    Phlip
    http://industrialxp.org/community/bin/view/Main/TestFirstUserInterfaces
     
    Phlip, Jul 9, 2004
    #3
    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. BlueDoze
    Replies:
    2
    Views:
    1,217
    Gordon Beaton
    May 4, 2004
  2. Robert Brewer
    Replies:
    1
    Views:
    517
    bsmith
    Nov 7, 2004
  3. Thomas Guettler

    assert 0, "foo" vs. assert(0, "foo")

    Thomas Guettler, Feb 23, 2005, in forum: Python
    Replies:
    3
    Views:
    2,562
    Carl Banks
    Feb 23, 2005
  4. Alex Vinokur

    assert(x) and '#define ASSERT(x) assert(x)'

    Alex Vinokur, Nov 25, 2004, in forum: C Programming
    Replies:
    5
    Views:
    956
    Keith Thompson
    Nov 25, 2004
  5. ImpalerCore

    To assert or not to assert...

    ImpalerCore, Apr 27, 2010, in forum: C Programming
    Replies:
    79
    Views:
    1,746
    Richard Bos
    May 17, 2010
Loading...

Share This Page