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

Macro compilation in C++

I am porting a C++ project that was using version 6 of the SDK to version 14.2 (big leap, I know). I want to use all the new bells and whistles from the new SDK that makes life easier, but I am getting some errors when wanting to emulate what is being done in the example code.

I am having a problem with this macro in particular:

NRF_SDH_SOC_OBSERVER()

When I try C++ compiling a macro that contains the one above, it gives me this error:

BLE_ADVERTISING_DEF(m_advertising);

../../nRF5_SDK_14.2.0_17b948a/components/ble/ble_advertising/ble_advertising.h:79:21: error: expected constructor, destructor, or type conversion before '(' token

Is there a proper way to use these macros in C++ or am I SOL?

Parents
  • Hi,

    Unfortunately, I do not see any way to use the macros with C++ as-is. These macros evalueate down to assignment of variables to members of a struct, like this:

    NRF_SECTION_SET_ITEM_REGISTER(sdh_soc_observers, _prio, static nrf_sdh_soc_evt_observer_t _name) =  \
    {                                                                                                   \
        .handler   = _handler,                                                                          \
        .p_context = _context                                                                           \
    }
    

    This format does not seem to be supported by C++ (specifying the name of the member that is being assigned). Instead, you will have to use this format:

    NRF_SECTION_SET_ITEM_REGISTER(sdh_soc_observers, _prio, static nrf_sdh_soc_evt_observer_t _name) =  \
    {                                                                                                   \
        _handler,                                                                          \
        _context                                                                           \
    }
    

    Note that this format is not as safe, as it will fail if you mess up the order of the assignments. I will report this issue internally, but I cannot guarantee that it will be fixed/changed. Our SDK is written to support C, and some of the coding methods is not well supported by C++.

    Best regards,

    Jørgen

Reply
  • Hi,

    Unfortunately, I do not see any way to use the macros with C++ as-is. These macros evalueate down to assignment of variables to members of a struct, like this:

    NRF_SECTION_SET_ITEM_REGISTER(sdh_soc_observers, _prio, static nrf_sdh_soc_evt_observer_t _name) =  \
    {                                                                                                   \
        .handler   = _handler,                                                                          \
        .p_context = _context                                                                           \
    }
    

    This format does not seem to be supported by C++ (specifying the name of the member that is being assigned). Instead, you will have to use this format:

    NRF_SECTION_SET_ITEM_REGISTER(sdh_soc_observers, _prio, static nrf_sdh_soc_evt_observer_t _name) =  \
    {                                                                                                   \
        _handler,                                                                          \
        _context                                                                           \
    }
    

    Note that this format is not as safe, as it will fail if you mess up the order of the assignments. I will report this issue internally, but I cannot guarantee that it will be fixed/changed. Our SDK is written to support C, and some of the coding methods is not well supported by C++.

    Best regards,

    Jørgen

Children
No Data
Related