1 /* @(#) assert.h 2.1 87/12/25 12:21:32 */ 2 3 /* 4 The contents of this file are hereby released to the public domain. 5 6 -- Rahul Dhesi 1991/07/04 7 8 Defines a macro assert() that causes an assertion error if the assertion 9 fails. 10 11 Conditional compilation: 12 13 If NDEBUG is defined then 14 assert() is defined as null so all assertions vanish 15 else 16 if __FILE__ and __LINE__ are defined then 17 assertions print message including filename and line number 18 else 19 assertions print a message but not the filename and line number 20 endif 21 endif 22 */ 23 24 #ifdef NDEBUG 25 # define assert(E) 26 #else 27 28 #undef LINE_FILE 29 30 #ifdef __LINE__ 31 # ifdef __FILE__ 32 # define LINE_FILE 33 # endif 34 #endif 35 36 #ifdef LINE_FILE 37 # undef LINE_FILE 38 # define assert(E) \ 39 { if (!(E)) \ 40 prterror ('w',"Assertion error in %s:%d.\n", __FILE__, __LINE__); \ 41 } 42 #else 43 # define assert(E) \ 44 { if (!(E)) \ 45 prterror ('w', "Assertion error.\n"); \ 46 } 47 #endif 48 #endif /* NDEBUG */ 49