Experimental Physics and
| |||||||||||||||
|
Unless I miss something then it seems to me that EPICS uses 'assert()' in the same way I often do which AFAIK is incorrect: assert( expression_with_side_effect ); because if the code is ever compiled with -DNDEBUG then the side effect (eg locking a mutex in epicsMutexMustLock()) *goes*away*. 'assert' is a macro which evaluates to nothing if NDEBUG is defined. The correct way of using assert would be: result = expression_with_side_effect; assert(result); but it is inconvenient because the message printed by a failed assertion would only say 'assertion of 'result' failed' and it would not print the stringified expression. My guess is that a lot of code would break if ever compiled with -DNDEBUG... Again: #define NDEBUG epicsMutexMustLock(my_lock); is a no-op! FWIW -- Till PS: It would be rather useful to have something like #ifdef NDEBUG #define usefulEpicsAssert(exp) (exp) #else #define usefulEpicsAssert(exp) ((exp) ? (void)(0) : assert(exp)) #endif
| ||||||||||||||
ANJ, 02 Sep 2010 |
·
Home
·
News
·
About
·
Base
·
Modules
·
Extensions
·
Distributions
·
Download
·
· Search · EPICS V4 · IRMIS · Talk · Bugs · Documents · Links · Licensing · |