comp.lang.ada
 help / color / mirror / Atom feed
From: Giuliano Carlini <giuliano@ix.netcom.com>
Subject: Re: Ada and C++ asserts.
Date: 1996/07/15
Date: 1996-07-15T13:39:29-05:00	[thread overview]
Message-ID: <31EA9015.5D9C@ix.netcom.com> (raw)
In-Reply-To: nh4tn9d9vw.fsf@paralysys


Nasser Abbasi wrote:
> 
> I am trying to keep an open mind about things, but see
> for yourself, a simple program to test assertions, the
> Ada version works fine, the C++ core dumps after it
> displays the assertion statment.

[SNIP: demonstration of Ada version working fine]

> C++ version
> ============
> 
> -------------------------------------------
> #include <assert.h>
> main()
> {
> int i=0;
> 
>     assert(i == 1);
>     return 0;
> }
> ------------------------------------------
> 
> .... now build and run
> 
> $CC t2.cc
> $a.out
> Assertion failed: i == 1, file t2.cc, line 8
> Abort (core dumped)
>       ^^^^^^^^^^^^^

I missed the articles leading up to this, and so I
may be misunderstanding what is being said. The only
reason this core dumps is because the implementation
of assert is something like this:
	#define assert(expr) \
		if ( !(expr) ) \
			assertFailed(#expr,__FILE__,__LINE__);
	void assertFailed( const char* expr, const char* file, unsigned line )
	{
		printf( "Assertion failed: %s, file %s, line %d\n", expr, file, line );
		abort();
	}
That is, the abort is intential. If you don't like it, it is easy to rewrite
assertFailed yourself. I've done this, and prefer:
	void assertFailed( const char* expr, const char* file, unsigned line )
	{
		throw AssertException( expr, file, line );
	}
No more core dump.

g




  reply	other threads:[~1996-07-15  0:00 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1996-07-15  0:00 Ada and C++ asserts Nasser Abbasi
1996-07-15  0:00 ` Giuliano Carlini [this message]
1996-07-15  0:00 ` Robert Dewar
1996-07-15  0:00 ` Nasser Abbasi
1996-07-16  0:00   ` Robert Dewar
1996-07-18  0:00   ` Ian Johnston
1996-07-22  0:00   ` Richard Curnow
1996-07-15  0:00 ` Fergus Henderson
1996-07-15  0:00 ` Stephen Leake
1996-07-16  0:00 ` Ian Johnston
1996-07-16  0:00 ` Eric Kline
1996-07-16  0:00   ` Jon S Anthony
1996-07-17  0:00 ` James McCallum
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox