Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs
This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Evaluating compound expression within ASSERT()

Hi, 

My app was written on Windows PC/MSVC and is ported to nRF52/Keil.

In many places I've used MSVC assert() macro in the following manners:

  • assert(function(arg1, arg2) == SUCCESS)
  • assert(ptr)
  • assert(ptr && intvar)

etc...

When porting it to nRF 52 I've tried to replace assert() with a generic MY_ASSERT() macro:

#if WINDOWS_PC

#define MY_ASSERT(cond)    assert((cond))

#else // nRF52+Keil

#define MY_ASSERT(cond)     ASSERT((cond))

#endif

Unfortunately when wrapping a function call+comparison MY_ASSERT(function(a,b) == SUCCESS), the source line is optimized out...

I tried to use ERROR_CHECK and also to implement do{int local_var = (cond); ASSERT(localVar);} while(0) type of tricks but it just doesn't work/compile

Any thoughts?

Thanks

Parents Reply Children
No Data
Related