|[26 earlier articles]|
|Re: failure due to compiler? email@example.com (1996-07-22)|
|Re: failure due to compiler? firstname.lastname@example.org (1996-07-22)|
|Re: failure due to compiler? email@example.com (Lee Webber) (1996-07-23)|
|Re: failure due to compiler? firstname.lastname@example.org (Eric Hamilton) (1996-07-23)|
|Re: failure due to compiler? email@example.com (1996-07-23)|
|Re: failure due to compiler? firstname.lastname@example.org (1996-07-24)|
|Re: failure due to compiler? email@example.com (1996-07-26)|
|'assert' peeves [was: failure due to compiler?] firstname.lastname@example.org (1996-07-27)|
|Re: failure due to compiler? email@example.com (1996-07-31)|
|Re: failure due to compiler? firstname.lastname@example.org (1996-07-31)|
|From:||email@example.com (Mike McCarty)|
|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|
)>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 <firstname.lastname@example.org> 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.
#define assert(x) ((void)0)
#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))
Return to the
Search the comp.compilers archives again.