Re: failure due to compiler?

jmccarty@sun1307.spd.dsccc.com (Mike McCarty)
26 Jul 1996 23:18:15 -0400

          From comp.compilers

Related articles
[26 earlier articles]
Re: failure due to compiler? ok@cs.rmit.edu.au (1996-07-22)
Re: failure due to compiler? rfg@monkeys.com (1996-07-22)
Re: failure due to compiler? leew@micrologic.com (Lee Webber) (1996-07-23)
Re: failure due to compiler? eric@gyst.com (Eric Hamilton) (1996-07-23)
Re: failure due to compiler? davidg@genmagic.com (1996-07-23)
Re: failure due to compiler? davidg@genmagic.com (1996-07-24)
Re: failure due to compiler? jmccarty@sun1307.spd.dsccc.com (1996-07-26)
'assert' peeves [was: failure due to compiler?] hagerman@ece.cmu.edu (1996-07-27)
Re: failure due to compiler? davidg@genmagic.com (1996-07-31)
Re: failure due to compiler? feliks@carlstedt.se (1996-07-31)
| List of all articles for this month |
From: jmccarty@sun1307.spd.dsccc.com (Mike McCarty)
Newsgroups: comp.compilers
Date: 26 Jul 1996 23:18:15 -0400
Organization: DSC Communications Corporation
References: 96-07-041 96-07-123 96-07-141 96-07-173
Keywords: errors

jgllgher@maths.tcd.ie says...
)>However, as expressions in C++ (and Eiffel) may have side effects, turning
)>assertion checking off may alter the behaviour of the program. One Eiffel
)>user I know claims to have experienced this perplexing behaviour. His
)>program worked as expected until he turned assertion checking off!


Dave Gillett <davidg@genmagic.com> wrote:
) The particular home-grown flavour of assertion-checking macro that I like
)has the "feature" of deliberately evaluating the tested expression *twice*.
)Code that relies on side-effects of such evaluation typically breaks while
)I'm still building debug versions.


Yes, that is a common flaw in <assert.h> implementations. DEC shipped
such a defective <assert.h> until I complained. Here is one which
I believe works. I typed it in just now, from a file which does work.
But I may have made a little typo. The __VAL__ __STR__ thing is a
standard trick used with the preprocessor to evaluate strings. Note that
the predicate is evaluated exactly once.


------------------------------------


#ifdef assert


#undef assert


#endif


#ifdef NDEBUG


#define assert(x) ((void)0)


#else


#define __ASSERT(x) ((void)(fputs("assertion failed: "),fputs(x,stderr),abort(),0)
#define __STR__(x) __VAL__(x)
#define __VAL__(x) #x
#define assert(x) ((x)?(void)0:__ASSERT(__FILE__ ":" __STR__(__LINE__) ": " #x))


#endif


------------------------------------


Mike
--
--


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.