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

Stray '##' in program

Hello all,

I'm still learning C at this point of stage. What I ended up was following a tutorial online on simple BLE project controlling the on-board LED.

The tutorial can be found here: https://www.novelbits.io/smart-ble-lightbulb-application-nrf52/

Everything great and wonderful, until I get to this piece of code here:

#define BLE_LED_SERVICE_DEF(_name);
static ble_led_service_t _name;                
// Compiler error - stray '##' in program
NRF_SDH_BLE_OBSERVER(_name ## _obs,                                   
                    BLE_LED_SERVICE_BLE_OBSERVER_PRIO,                
                    ble_led_service_on_ble_evt, &_name);       

I get a compiler error complaining that there's a stray symbol in my program. The symbol the compiler doesn't understand is '##'. I thought this has to do with the fact that the compiler doesn't understand ASCII characters or UTF-8 Characters, but seeing that Segger Embedded Studio forces input into ASCII text is not the issue...

When I expand "NRF_SDH_BLE_OBSERVER", all it does is creating a new macro to register the observer event into the memory and wait for softdevice handle to reference it at runtime.

#define NRF_SDH_BLE_OBSERVER(_name, _prio, _handler, _context)                                      \
STATIC_ASSERT(NRF_SDH_BLE_ENABLED, "NRF_SDH_BLE_ENABLED not set!");                                 \
STATIC_ASSERT(_prio < NRF_SDH_BLE_OBSERVER_PRIO_LEVELS, "Priority level unavailable.");             \
NRF_SECTION_SET_ITEM_REGISTER(sdh_ble_observers, _prio, static nrf_sdh_ble_evt_observer_t _name) =  \
{                                                                                                   \
    .handler   = _handler,                                                                          \
    .p_context = _context                                                                           \
}

From my understanding behind the code "##" is to append anything on the right side of the operator to the left side variable as a new variable name (e.g. test ## _obs becomes test_obs ) before passing into the function above.
I'm pretty stump at this point, is this a compiler issue? And if so, what do I need to do to fix this issue?

The Segger Embeeded Studio version is 2020042000.41974 (Release 4.52b Build)

The nRF5 SDK was the latest copy I've download from NordicSemiconductor website. (Version v16.0.0)

Thanks in advance,

JB.

Related