In my search for new strategeis for writing bug free embedded code and debugging the code quickly, I came across about assert() function. By simple googling i found it as useful to find which expression (or) variable (or) line of code made my code not to work as defined.
Quickly i tried a simple test code in keil. But it did not show me any error message.
Help me regarding why i am not able get any error message. Also i recognised (in dis-assembly window) that the code continue to execute different library functions and never come out. Given below is my test code.
#include <assert.h> int myfunc (int arg) { arg=0; return(arg); } void child_func (int arg1) { ; } int main(void) { short int temp_var=0; while(1) { int temp_var1; temp_var1=myfunc(temp_var); assert(temp_var1!=0); child_func(temp_var1); } }
So you need to keep googling to find out how to use it properly!
Specifically, what other arrangements do you need to make to have assert() produce error messages...
assert is expected to result in a printout in case of a failed condition.
But embedded devices does not normally have any natural consoles. So it's up to the developer to set up a route for printed output - like sending the text to a specific UART.
Or you might not want printed output at all!
eg, you might just save some kind of "event log" in memory...