[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: assert vs. abort
From: |
Ben Pfaff |
Subject: |
Re: assert vs. abort |
Date: |
Mon, 03 Apr 2006 08:03:22 -0700 |
User-agent: |
Gnus/5.110004 (No Gnus v0.4) Emacs/21.4 (gnu/linux) |
John Darrington <address@hidden> writes:
> On Sat, Apr 01, 2006 at 11:16:42AM -0800, Ben Pfaff wrote:
>
> > How about this:
> >
> > ASSERT() -- for cheap, important checks
> > ASSERT1() -- for more expensive or less important checks
> > ASSERT2() -- for expensive checks
> > ASSERT_LEVEL -- if defined to a number, checks at the given
> > level or higher are disabled.
> > NOT_REACHED() -- as discussed
> Doesn't this still leave a problem if we want to add a level between 1
> & 2 ?
I am confused why we would want to do that. I wouldn't think
we'd want more than a couple of levels.
However--I haven't had much experience with multiple levels of
assertions. Have you? If you do, then perhaps your experience
can guide our choices.
> I would perform the following sedscript on the above.
> s/ASSERT1/ASSERT_EXPENSIVE/ s/ASSERT2/ASSERT_VERY_EXPENSIVE/
> s/\ 1/\ 10/ s/\ 2/\ 20/
My main objection is that something like ASSERT_VERY_EXPENSIVE is
too long. Is there a shorter way to express the same intent?
> > * NOT_REACHED should *always* be enabled.
>
> ...though I'd argue that it should just expand to abort() when
> all assertions are otherwise disabled.
>
> I'd have to respectfully disagree. Our "You have discovered a
> bug...." message has brought a number of bug reports which I believe
> would otherwise have gone unreported. Many people won't take the
> effort to report a bug if the program just terminates with the rather
> concise message "Aborted".
You may be right.
However, I only meant to suggest that NOT_REACHED() should just
expand to abort() when *all* assertions were disabled, i.e. at
ASSERT_LEVEL 0.
--
"Ho ho ho. I _so_ enjoy making a fool out of myself."
--Linus, on Christmas Day, 2000