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

ble_db_discovery.h not compatible with C++

When I try to use SDK in C++ project with GCC 7 I get:

SDK/components/ble/ble_db_discovery/ble_db_discovery.h:92:84: sorry, unimplemented: non-trivial designated initializers not supported

That's because not all fields are initialized:

static ble_db_discovery_t _name = {.discovery_in_progress = 0,                          \
                                   .discovery_pending     = 0,                          \
                                   .conn_handle           = BLE_CONN_HANDLE_INVALID};   \

The fix is very easy for Nordic to implement. Just add missing initializers:

static ble_db_discovery_t _name = {.services = {0}, 								\
								.srv_count = 0, 									\
								.curr_char_ind = 0,									\
								.curr_srv_ind = 0,									\
								.discovery_in_progress = 0,                         \
                                .discovery_pending     = 0,                         \
								.discoveries_count = 0,								\
		                        .conn_handle           = BLE_CONN_HANDLE_INVALID};  \

Parents Reply Children
  • I know that very well. On the other hand Nordic has already made changes to SDK to make it C++ compatible. Note for example extern "C" in .c files belonging to SDK. Other incompatibilities has also been fiexed. Nordic doesn't claim SDK to be C++ compatible but cares about it. I'm just asking for one more fix and I'm providing it. Moreover the patch is also good from C point of view because now some fields are left uninitialized which is bad practice.

Related