From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=0.2 required=5.0 tests=BAYES_00,INVALID_MSGID, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,a0e076952eca80d4 X-Google-Attributes: gid103376,public From: Giuliano Carlini Subject: Re: Ada and C++ asserts. Date: 1996/07/15 Message-ID: <31EA9015.5D9C@ix.netcom.com>#1/1 X-Deja-AN: 168883570 references: content-type: text/plain; charset=us-ascii organization: Netcom x-netcom-date: Mon Jul 15 1:39:29 PM CDT 1996 mime-version: 1.0 reply-to: giuliano@ix.netcom.com newsgroups: comp.lang.ada x-mailer: Mozilla 3.0b4Gold (Win95; I) Date: 1996-07-15T13:39:29-05:00 List-Id: 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 > 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