can assert() hide debug dump out?

J

John Black

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?
 
V

Victor Bazarov

John said:
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
 
P

Phlip

John said:
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.
 

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,777
Messages
2,569,604
Members
45,234
Latest member
SkyeWeems

Latest Threads

Top