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 / 2321
2320  |  2322
Subject: 
Re: Design by Contract (long post)
Newsgroups: 
lugnet.robotics.rcx
Date: 
Thu, 8 Jan 2004 16:57:55 GMT
Viewed: 
2995 times
  
In lugnet.robotics.rcx, Ross Crawford wrote:
  
  
#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

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, this thread should of course have been in the BrickOS group. Noob mistake :)



Message is in Reply To:
  Re: Design by Contract (long post)
 
(...) Hi Iain! (...) Cool! (...) 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 (...) (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
    

Custom Search

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