Subject:
|
Re: Design by Contract (long post)
|
Newsgroups:
|
lugnet.robotics.rcx
|
Date:
|
Thu, 8 Jan 2004 16:52:02 GMT
|
Viewed:
|
3110 times
|
| |
![Post a public reply to this message](/news/icon-reply.gif) | |
In lugnet.robotics.rcx, Tim McSweeney wrote:
|
<delurk>
The first definition of assert is the correct, standard definition. However
there is a slight boo boo in the original post in the line:
assert (myptr = malloc (sizeof (mystruct));
Which will delete the malloc when NDEBUG is defined. Its a classic mistake
that bites even experienced programmers now and then.
the easy way round it is to write:
myptr = malloc (sizeof (mystruct));
assert(myptr!=NULL);
thus, the malloc always takes place, but the assert only occurs in debug
builds.
|
DoH! Thanks, Tim. I was very careful composing the original post, but added
the example in as an after thought - Well spotted.
Iain.
|
|
Message has 1 Reply: ![](/news/x.gif) | | Re: Design by Contract (long post)
|
| (...) For more fun with asserts: See if your compiler supports the FILE and LINE macros (or something equivilant). #ifdef NDEBUG #define assert(x) ((void)0) #else #define assert(x) if (x) else assertfail(FILE,LINE); #endif your assert_fail function (...) (20 years ago, 9-Jan-04, to lugnet.robotics.rcx, FTX)
|
Message is in Reply To:
![](/news/x.gif) | | Re: Design by Contract (long post)
|
| (...) <delurk> The first definition of assert is the correct, standard definition. However there is a slight boo boo in the original post in the line: assert (myptr = malloc (sizeof (mystruct)); Which will delete the malloc when NDEBUG is defined. (...) (20 years ago, 8-Jan-04, to lugnet.robotics.rcx, FTX)
|
7 Messages in This Thread: ![Design by Contract (long post) -Iain McInnes (8-Jan-04 to lugnet.robotics.rcx)](/news/x.gif) ![](/news/46.gif) ![Re: Design by Contract (long post) -Ross Crawford (8-Jan-04 to lugnet.robotics.rcx)](/news/x.gif) ![](/news/246.gif) ![Re: Design by Contract (long post) -Tim McSweeney (8-Jan-04 to lugnet.robotics.rcx)](/news/x.gif) ![](/news/46.gif) ![You are here](/news/here.gif) ![](/news/46.gif) ![Re: Design by Contract (long post) -Tim McSweeney (9-Jan-04 to lugnet.robotics.rcx)](/news/x.gif) ![](/news/46.gif) ![Re: Design by Contract (long post) -Iain McInnes (10-Jan-04 to lugnet.robotics.rcx)](/news/x.gif)
![](/news/x.gif) ![](/news/x.gif) ![](/news/68.gif) ![Re: Design by Contract (long post) -Iain McInnes (8-Jan-04 to lugnet.robotics.rcx)](/news/x.gif)
- Entire Thread on One Page:
- Nested:
All | Brief | Compact | Dots
Linear:
All | Brief | Compact
This Message and its Replies on One Page:
- Nested:
All | Brief | Compact | Dots
Linear:
All | Brief | Compact
|
|
|
|