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 / 2324
2323  |  2325
Subject: 
Re: Design by Contract (long post)
Newsgroups: 
lugnet.robotics.rcx
Date: 
Sat, 10 Jan 2004 10:24:28 GMT
Viewed: 
3547 times
  
Thanks, Tim.

I haven’t used the #x idiom myself - I like it. Your implementation with the boolean:

  
#ifdef NDEBUG
#define assert(x) ((void)0)
#else
#define assert(x)                                           \
    static bool bIsDisabled = false;                        \
    if (x)                                                  \
    {}                                                      \
    else                                                    \
    {                                                       \
        if(!bIsDisabled)                                    \
        {                                                   \
            assert_fail(__FILE__,__LINE__,#x,&bIsDisabled); \
        }                                                   \
    }
#endif


Will need an extra level of parenthesis surrounding the bool so that its declaration scope is made local.

You can certainly go to town with this stuff. At work, we are spoiled - we are developing on a Linux target. So actually, we never turn the asserts off. When developing (!NDEBUG) the assert behaves as discussed. For final test and field operation (NDEBUG) The condition is still checked, and a syslog message is generated. It can be fun writing the defensive code that tries to get the machine back to a sane state :)

Iain.



Message is in Reply To:
  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 (...) (21 years ago, 9-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