Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Better assert
#1
Hi,
I have to send assert output through canbus to the display unit.
At present my assert looks like this:
.h file
#define assert(left,operator,right)\
    if(!((left) operator (right))) \
     {asprintf(&astrbuf,"\nAssert error %s %d %ld %ld\n",__FILE__, __LINE__,\
      (u32)(left),(u32)(right));\
      asserted();\
     }

.c file
void asserted(void)
{ dprint("%s",astrbuf);
  dispstart;
  cmd_text(10,50,30,0, astrbuf);
  free(astrbuf);
  dispend;
This is followed by the code to switch off outputs.

This works very well, example:
assert(millis, <, maxtime);

What irks me is that I cannot see how to send the operator to asprintf.
It would be so much better if the operator could also be displayed.
Any help will be appreciated.
Thank you
Johan Smit
Reply
#2
The answer of course is the stringizing operator.
I feel such a fool.
Corrected h file:
extern char *astrbuf;
#define assert(left,operator,right)\
    if(!((left) operator (right))) \
     {asprintf(&astrbuf,"\nAssert error %s %d %ld %s %ld\n",__FILE__, __LINE__,\
      (u32)(left), #operator, (u32)(right));\
      asserted();\
     }
Works perfectly.
Johan Smit
Reply
#3
Top John!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)