0

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.

Community
  • 1
  • 1
Vorac
  • 8,726
  • 11
  • 58
  • 101

2 Answers2

4

The file name is probably a string constant (const char*), but your function takes a char* parameter. This mismatch causes the error.

If you declare the function parameter as const char *fname instead, the error should go away.

sth
  • 222,467
  • 53
  • 283
  • 367
2

Redefine you function:

void handleCriticalError(int err_num, char const *fname, int line_num, const char *foo);

note const *fname parameter that should accept __FILE__

dmitri
  • 3,183
  • 23
  • 28