public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* Keeping assert's active when not in debug mode?
@ 2008-07-12  2:36 Christian Convey
  2008-07-12  4:56 ` me22
  0 siblings, 1 reply; 2+ messages in thread
From: Christian Convey @ 2008-07-12  2:36 UTC (permalink / raw)
  To: gcc-help

Is there any way I can make assert(...) macro invocations still do
their magic, even when I build my software for release (e.g., not with
the "-g" option)?

I'd really like to keep them active, so that we can more easily detect
flaws in the released version of the software.

If I can't make assert(...) calls work, any suggestions for what to
use instead?  Maybe something like this? (I know I'd need to fix some
preprocessor issues for the macro...)

#define my_assert(predicate) {
#ifdef DEBUG
   assert(predicate);
#else
   if (! (predicate)) {
      error_at_line(1, 1, __FILE__, __LINE__, "predicate");
   }
#endif
}


Thanks,
Christian

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Keeping assert's active when not in debug mode?
  2008-07-12  2:36 Keeping assert's active when not in debug mode? Christian Convey
@ 2008-07-12  4:56 ` me22
  0 siblings, 0 replies; 2+ messages in thread
From: me22 @ 2008-07-12  4:56 UTC (permalink / raw)
  To: Christian Convey; +Cc: gcc-help

On Fri, Jul 11, 2008 at 22:14, Christian Convey
<christian.convey@gmail.com> wrote:
> Is there any way I can make assert(...) macro invocations still do
> their magic, even when I build my software for release (e.g., not with
> the "-g" option)?
>

Using a custom assert macro is the most obvious way, probably, but you
could also use a custom myassert.h header that contains something like
this:

#ifdef NDEBUG
#    define ACTUALLY_IN_NDEBUG_MODE
#    undef NDEBUG
#end
#include <assert.h>
#ifdef ACTUALLY_IN_NDEBUG_MODE
#    define NDEBUG
#    undef ACTUALLY_IN_NDEBUG_MODE
#endif

But note that -g doesn't actually turn off asserts, so unless you're
using NDEBUG explicitly, you don't need to do anything.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2008-07-12  2:36 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-07-12  2:36 Keeping assert's active when not in debug mode? Christian Convey
2008-07-12  4:56 ` me22

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).