1

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

Steve Friedl
  • 3,929
  • 1
  • 23
  • 30
Guillaume D
  • 2,202
  • 2
  • 10
  • 37
  • TL;DR of dupe: Use `_Pragma`, replacing `#pragma warning disable/enable Pe225` with `_Pragma("warning disable/enable Pe225")` – Artyer Feb 26 '20 at 15:45
  • 1
    You say that you don't care about the warning, but your understanding of why the warning is happening is wrong, and it's easy to fix. Change `printf("Function call to "#function" did not crash : OK \n",NULL);` to `printf("Function call to %s did not crash: OK\n", #function);` and the warning should go away. – zwol Feb 26 '20 at 15:45
  • it's not working:```#pragma warning disable Pe225``` ---> ```Warning[Pe161]: unrecognized #pragma ``` – Guillaume D Feb 26 '20 at 15:48
  • thanx zwol you saved my life – Guillaume D Feb 26 '20 at 15:49

0 Answers0