This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

APP_ERROR_CHECK usage pattern

Hello, while reading some nrf5 examples, I've stumbled over a pattern in the examples, where the result code of a function is stored in variable (most of the time named err_code) and then this variable is passed to APP_ERROR_CHECK. Intuitivly, I would directly pass the funtion result to the APP_ERROR_CHECK macro ("APP_ERROR_CHECK( f() )"). Is there any particular reason for this pattern, or is it just a "habit" comming the pitfalls when using assert?

Is it safe to directly pass the return value of a function call to APP_ERROR_CHECK (I found nothing in the documentation, nor the implementation that tells that the argument to the macro would not be evaluated or would be evaluated more than once).

kind regards,

Torsten

Parents
  • Doesn't matter a damn, do whichever you like. However if you are debugging/single-stepping the code it's easier to have it on two lines so you can see the value of the variable before you enter the APP_ERR_CHECK() and go to the fault handler.

    In release code it's all optimized anyway so either piece of code ends up looking exactly the same.

    Use whichever suits your own personal style, I usually do it all on one line, unless that makes the line incredibly long, in which case I split it up.

Reply
  • Doesn't matter a damn, do whichever you like. However if you are debugging/single-stepping the code it's easier to have it on two lines so you can see the value of the variable before you enter the APP_ERR_CHECK() and go to the fault handler.

    In release code it's all optimized anyway so either piece of code ends up looking exactly the same.

    Use whichever suits your own personal style, I usually do it all on one line, unless that makes the line incredibly long, in which case I split it up.

Children
Related