Looking for implementing the EXPECT_NO_CRASH
from this link directly in embedded software with an UART com ongoing on a terminal.
The purpose is just simple:
If the function call works ok, the "OK" is printed, if the program crashes, nothing is displayed on the terminal.
How did I implemented it?
#define CALL_DID_NOT_CRASH do{ function; printf("Function call to "#function" did not crash : OK \n",NULL); }while(0)
How to use it?
CALL_DID_NOT_CRASH(myFunction(1,2,3));
returns if call is ok:
Function call to myFunction(1,2,3) did not crash : OK
otherwise return nothing, system is stopped/frozen, or reset.
The only problem I have is this warning:
Warning[Pe225]: the format string ends before this argument
I know why, it is because there is two ')' in the macro call and because of the first comma ',' which ends the macro argument:
CALL_DID_NOT_CRASH(myFunction(1,2,3));
-------------------------------^---^^
But I don't care because it works.
I'm using IAR 8.20.2, how to get rid of this warning but only for each call of this macro? I was thinking of a #pragma...but the '#' bothers me...
#define CALL_DID_NOT_CRASH do{ #pragma warning disable Pe225 function; printf("Function call to "#function" did not crash : OK \n",NULL); #pragma warning restore Pe225 }while(0)
Error[Pe020]: identifier "pragma" is undefined