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

Alternative to NRF_MODULE_ENABLED system?

We are all familiar with NRF_MODULE_ENABLED macros, what is their purpose and why are they required.

However, I am wondering if there could be a better way to implement such selection system, one which would be "future proof" - GCC 7 and Clang emits warning -Wexpansion-to-defined for such macros.

The warning can be suppressed, however this behaviour pulls other problems with it - as example, I described one of the most annoying in the JetBrains ticket 'defined' preprocessor operator and token concatenation, because I thought that is their bug.

I know that older SDKs had a system which actually didn't have that problem, however I do agree that this new system is more elegant and practical. Is there any compromise between the two?

  • I found a solution.

    It is quite a strict one, but luckily long ago I took a time to compare numerous sdk_config.h files to make one with all configuration defines in it.
    I changed

    //lint -emacro(491,NRF_MODULE_ENABLED) // Suppers warning 491 "non-standard use of 'defined' preprocessor operator"
    #define NRF_MODULE_ENABLED(module) \
        ((defined(module ## _ENABLED) && (module ## _ENABLED)) ? 1 : 0)

    to

    #define NRF_MODULE_ENABLED(module) ((module ## _ENABLED) ? 1 : 0)

    in the nordic_common.h file. Now everything is working fine.

Related