In assert.h
we can see
# define assert(__e) ((__e) ? (void)0 : __assert_func (__FILE__, __LINE__, \
__ASSERT_FUNC, #__e))
Because the target is embedded, I need to actually display the error message upon assertion failure, so I need to invoke the LCD write function. I tried the following:
void handleCriticalError(int err_num, char *fname, int line_num, const char *foo); // Halts the program!
#define ASSERT(__e) ((__e) ? (void)0 : handleCriticalError (0, __FILE__, __LINE__, __func__))
However, when I use it, I get a strange error.
ASSERT(1<2);
>error: deprecated conversion from string constant to 'char*' [-Werror=write-strings]
How do I tie my function to a custom assert, or to the standard assert, so that the function is called upon failed assertion?
Note that I do not need a full-featured, standard-adhering assert
as is discussed here. I am going to use it only as single statements on a line, with a simple comparison of variables or constants.