Saturday, 26 May 2012

How assert macro can help in embedded systems?

Have you seen any time these type of print messages?

Assertion NULL, failed at ../../abc.c 876
Assertion NULL, failed at ../../abc.c 876
Assertion NULL, failed at ../../abc.c 876
Assertion 0, failed at ../../abczy.c 987


Syntex is 


void assert ( int expression ) ;


The expression is evaluated and if it evaluates to zero, it causes assertion failure and that terminates the program.


In production generally it is not used and to disable this macro use 


#define NDEBUG before the inclusion of assert.h


There is a great discussion about which is better way to use this macro, if you know these messages you should go through this discussion once...




http://bytes.com/topic/c/answers/479154-how-does-assert-benefit-your-code-really/2