home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / snip9707.zip / STK_DEFS.H < prev    next >
C/C++ Source or Header  |  1997-07-05  |  3KB  |  68 lines

  1. /* +++Date last modified: 05-Jul-1997 */
  2.  
  3. /*  ======================================================================
  4.     DEFINES.h       Standard definitions etc.
  5.                     For simplification or for debugging substitution.
  6.  
  7.                     A.Reitsma, Delft, Nederland.
  8.                     v0.23  94-07-02
  9. ----------------------------------------------------------------------- */
  10.  
  11. #ifndef STK_DEFS_H
  12. #define STK_DEFS_H
  13.  
  14. #include <stdio.h>
  15. #include <stdlib.h>
  16. #include <string.h>
  17.  
  18. typedef unsigned char       byte;
  19. typedef unsigned short      byte2;
  20. typedef unsigned long       byte4;
  21. typedef unsigned int        word;
  22.  
  23. #define MALLOC(size,type)   (type *) malloc( (size) * sizeof( type ))
  24. #define FREE(mem)           free( mem )
  25. #define CALLOC(size,type)   (type *) calloc( (size), sizeof( type))
  26.  
  27. #ifdef DEBUG_NPA
  28.  
  29. extern void * NPAdata ;     /* Declare it in the main() file !!!       */
  30.  
  31. #if sizeof( void * ) != sizeof( void far * )   /* small data models */
  32. #define NPAsize             0x40
  33. #else
  34. #define NPAsize             0x100 * sizeof( void far * )
  35. #endif                      /* protect interrupt vectors for
  36.                                large data models                       */
  37.  
  38. #define NPAinit()           NPAdata = malloc( NPAsize );      \
  39.                             memcpy( NPAdata, NULL, NPAsize )
  40.                             /* call NPAinit as first function in main() */
  41.  
  42. #define NPAcheck()          if( memcmp( NPAdata, NULL, NPAsize ))        \
  43.                             {   printf( "\aNPA before line %d"           \
  44.                                     " in file %s", __LINE__, __FILE__ ); \
  45.                                 memcpy( NULL, NPAdata, NPAsize );        \
  46.                             }
  47. #if 0
  48. #define return(x)           { NPAcheck(); return(x); }
  49.                             /* does NOT work for format "return XXX ;"  */
  50. #else
  51. #define return              NPAcheck(); return
  52.                             /* does also work for format "return XXX ;" */
  53. #endif                      /* but not for:
  54.                                   if(...) return ...;  without { }      */
  55.                             /* that causes warnings of unreachable code */
  56. #pragma warn +rch           /* when switched on with this pragma ...    */
  57.                             /* TC2.0, BC3.1 */
  58. #else
  59.  
  60. #define NPAinit()
  61. #define NPAcheck()
  62.  
  63. #endif
  64.  
  65. #endif /* STK_DEFS_H */
  66.  
  67. /*  === DEFINES.h end ================================================= */
  68.