To LUGNET HomepageTo LUGNET News HomepageTo LUGNET Guide Homepage
 Help on Searching
 
Post new message to lugnet.robotics.rcxOpen lugnet.robotics.rcx in your NNTP NewsreaderTo LUGNET News Traffic PageSign In (Members)
 Robotics / RCX / 2317
2316  |  2318
Subject: 
Re: Design by Contract (long post)
Newsgroups: 
lugnet.robotics.rcx
Date: 
Thu, 8 Jan 2004 08:53:27 GMT
Viewed: 
2949 times
  
In lugnet.robotics.rcx, Iain McInnes wrote:
   Hi, people.

Hi Iain!

   I have created an assert() macro which works under BrickOS. For those unfamiliar with assert(), it is a standard C macro whose purpose is to help find bugs. It is integral to the ‘design by contract’ style of programming pioneered by Bertrand Meyer.

Cool!

  
#ifdef NDEBUG
#define assert(x) ((void)0)
#else
#define assert(x) if (x) {} else { assert_fail(); }
#endif

I have a question about this: If NDEBUG is defined, shouldn’t it still execute x? That is, shouldn’t the code in assert.h (or wherever) be:
#ifdef NDEBUG
#define assert(x) (x)
#else
#define assert(x) if (x) {} else { assert_fail(); }
#endif
ROSCO



Message has 2 Replies:
  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)
  Re: Design by Contract (long post)
 
(...) I agree it seems to be the wrong way round. That's the standard implementation. NDEBUG seems to stand for "No debug". One advantage of making it negative, is that you get the assert()s if you don't do anything (ie dont define NDEBUG). BTW, (...) (20 years ago, 8-Jan-04, to lugnet.robotics.rcx, FTX)

Message is in Reply To:
  Design by Contract (long post)
 
Hi, people. The reason for the flood of posts is that I've been trying to get authenticated on LUGNET for the last week :( But as you can see, I'm authenticated now :) On to the topic of this post (sorry for such a long post): I have created an (...) (20 years ago, 8-Jan-04, to lugnet.robotics.rcx, FTX)

7 Messages in This Thread:


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
    

Custom Search

©2005 LUGNET. All rights reserved. - hosted by steinbruch.info GbR