home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional / OS2PRO194.ISO / os2 / sysutils / mshell / source / pmassert.h < prev    next >
Encoding:
C/C++ Source or Header  |  1993-10-16  |  1.5 KB  |  55 lines

  1. /****************************************************************************
  2. * name: pmassert.h
  3. *
  4. * description: similar to C assert.h, but presents debugging information
  5. *   in a PM message box instead of standard error.
  6. *
  7. *   The pmassert macro works when the symbol NDEBUG is not defined to the
  8. *   compiler; thus, the macro works by default.
  9. *
  10. *   To build a non-debug version of the program, define the symbol NDEBUG
  11. *   with the proper compiler switch, usually /DNDEBUG
  12. *
  13. *   The message box shows the last error in hex. The high word is severity,
  14. *   and the low word is an error code. Refer to pmerr.h for an explanation
  15. *   of the error code.
  16. *
  17. *   Do not pmassert any assignment statements or function calls, for these
  18. *   statements will vanish in the non-debug version of the code. Assert only
  19. *   Boolean expressions you think should always be true.
  20. *
  21. ****************************************************************************/
  22.  
  23. #ifndef NDEBUG
  24.  
  25. #define pmassert(hab,exp)\
  26. {\
  27. if(!(exp)) {\
  28.   char ebuff[ 64 ]; \
  29.   unsigned long errorid; \
  30.   unsigned short usrc;\
  31.   errorid = WinGetLastError( hab ); \
  32.   sprintf( ebuff, "Line %d\nFile %s\nLast Error %p\nExpression %s\n", __LINE__, __FILE__, errorid, #exp );\
  33.   usrc = WinMessageBox( HWND_DESKTOP, HWND_DESKTOP, ebuff, "Assertion failed. Continue?", 0, MB_YESNO  );\
  34.   if( usrc == MBID_NO ) exit( 1 );\
  35. }\
  36. }
  37.  
  38. #define dbprintf(exp)   printf exp
  39.  
  40.  
  41.  
  42. #else
  43.   #define pmassert(hab,exp)
  44.   #define dbprintf(exp)
  45. #endif
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55.