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};  \

Related