Figure 1: A few new assertion macros

//================================================
// Some debugging macros by G.Bavestrelli     
// Copyright Techint S.p.A. 1994-1999 
// Any feedback is welcome, you can contact me at 
// giovanni.bavestrelli@pomini.it
//================================================

// Undefine the standard MFC assertion macros
#undef  ASSERT
#undef  VERIFY

#ifdef _DEBUG
  // My assertion routine
  void 
  GioAssertFailedLine(LPCSTR file, int line, LPCSTR expression);

  // Main assert macros
  #define ASSERT(v) \
    (!(v) && (GioAssertFailedLine(THIS_FILE,__LINE__,#v),0))
  #define VERIFY(v) ASSERT(v)
  #define SAFE(v)   (ASSERT(v),(v))

  // Secondary assert macros
  #define ASSERT_ONCE(v) { static int k=0; \
    (!(v) && !k++ && \
    (GioAssertFailedLine(THIS_FILE,__LINE__,#v),0));}
  #define ASSERT_LEN(str) \
    ASSERT((str) && lstrlen(str)<sizeof(str))
  #define ASSERT_ARRAYINDEX(a,i) \
    ASSERT((i)>=0 && (i)<ARRAYSIZE(a))
#else
  // Main assert macros in release mode disappear
  #define ASSERT(v)     ((void)(0))
  #define VERIFY(v)     ((void)(v))
  #define SAFE(v)       (v)

  // Secondary assert macros in release mode disappear
  #define ASSERT_ONCE(x)         {}
  #define ASSERT_LEN(str)        ((void)(0))
  #define ASSERT_ARRAYINDEX(a,i) ((void)(0))
#endif