Hi, Iam trying to run c++ code on nrf52840.
I got working C code, so i try only change .c to .cpp. I got some errors but most of them are solvable by putting libraries(.h files) in: extern "C" {};
The problem is with these macros:
NRF_BLE_GATT_DEF(m_gatt); NRF_BLE_QWR_DEF(m_qwr); BLE_ADVERTISING_DEF(m_advertising); APP_TIMER_DEF(m_app_timer_id); BLE_MY_DEF(ble_service);
This macros throwing this error: sorry, unimplemented: non-trivial designated initializers not supported
Because this code work under C compiler i assume this is a g++ compiler error.
However i could resolve this error by running gcc with -E flag that resolve macros and outputs plain c code. From this code i got this:static nrf_ble_gatt_t m_gatt; extern char (*_do_assert(void)) [sizeof(char[1 - 2*!(1)])]; extern char (*_do_assert(void)) [sizeof(char[1 - 2*!(1 < 4)])]; static nrf_sdh_ble_evt_observer_t m_gatt_obs __attribute__ ((section("." "sdh_ble_observers1"))) __attribute__((used)) = { .handler = nrf_ble_gatt_on_ble_evt, .p_context = &m_gatt };
static nrf_ble_qwr_t m_qwr; extern char (*_do_assert(void)) [sizeof(char[1 - 2*!(1)])]; extern char (*_do_assert(void)) [sizeof(char[1 - 2*!(2 < 4)])]; static nrf_sdh_ble_evt_observer_t m_qwr_obs __attribute__ ((section("." "sdh_ble_observers2"))) __attribute__((used)) = { .handler = nrf_ble_qwr_on_ble_evt, .p_context = &m_qwr };
static ble_advertising_t m_advertising; extern char (*_do_assert(void)) [sizeof(char[1 - 2*!(1)])]; extern char (*_do_assert(void)) [sizeof(char[1 - 2*!(1 < 4)])]; static nrf_sdh_ble_evt_observer_t m_advertising_ble_obs __attribute__ ((section("." "sdh_ble_observers1"))) __attribute__((used)) = { .handler = ble_advertising_on_ble_evt, .p_context = &m_advertising };
static app_timer_t m_app_timer_id_data = { {0} }; static const app_timer_id_t m_app_timer_id = &m_app_timer_id_data;
static my_ble_service ble_service; extern char (*_do_assert(void)) [sizeof(char[1 - 2*!(1)])]; extern char (*_do_assert(void)) [sizeof(char[1 - 2*!(2 < 4)])]; static nrf_sdh_ble_evt_observer_t ble_service_obs __attribute__ ((section("." "sdh_ble_observers2"))) __attribute__((used)) = { .handler = on_ble_evt, .p_context = &ble_service };
Every line corresponds for one of the macros. (this code runs without problems under g++).
And after removing things like extern char (*_do_assert(void)) [sizeof(char[1 - 2*!(1)])]; i get this result. (also working)
//NRF_BLE_GATT_DEF(m_gatt);
static nrf_ble_gatt_t m_gatt;
static nrf_sdh_ble_evt_observer_t m_gatt_obs __attribute__ ((section("." "sdh_ble_observers1"))) __attribute__((used)) = { .handler = nrf_ble_gatt_on_ble_evt, .p_context = &m_gatt };
//NRF_BLE_QWR_DEF(m_qwr);
static nrf_ble_qwr_t m_qwr;
static nrf_sdh_ble_evt_observer_t m_qwr_obs __attribute__ ((section("." "sdh_ble_observers2"))) __attribute__((used)) = { .handler = nrf_ble_qwr_on_ble_evt, .p_context = &m_qwr };
//BLE_ADVERTISING_DEF(m_advertising);
static ble_advertising_t m_advertising;
static nrf_sdh_ble_evt_observer_t m_advertising_ble_obs __attribute__ ((section("." "sdh_ble_observers1"))) __attribute__((used)) = { .handler = ble_advertising_on_ble_evt, .p_context = &m_advertising };
//APP_TIMER_DEF(m_app_timer_id);
static app_timer_t m_app_timer_id_data = { {0} };
static const app_timer_id_t m_app_timer_id = &m_app_timer_id_data;
//BLE_MY_DEF(ble_service);
static my_ble_service ble_service;
static nrf_sdh_ble_evt_observer_t ble_service_obs __attribute__ ((section("." "sdh_ble_observers2"))) __attribute__((used)) = { .handler = on_ble_evt, .p_context = &ble_service };
But this approach have problem that the code is not much readable. (although the strip version is much better).
So my question is:
Is there any way to not use these macros and get same result. Some functions / class / struct or something like that?
Or is there any way to use these macros in c++ code?
And also if there is not other way can this approach has some problem or can become problem when code be expanded?
And small curiosity question. What this code mean extern char (*_do_assert(void)) [sizeof(char[1 - 2*!(1)])];, because its generated but i don't think it do anything?