c++nrf52

How can I casting void * to void **?


I make some project to using nRF52833 by CPP.

I need to add NUS(Nordic Uart Service) in my project. But I have some problem.

Nrf library NUS using ble_nus.c file. I try to build by CPP compiler but some error occur.

Error message is this. Error[Pe167]: argument of type "void *" is incompatible with parameter of type "void **" C:\git\heden_ble\src\components\ble\ble_services\ble_nus\ble_nus.c 139

ble_nus.c file has four error points.

How can I casting void * to void **

ble_nus_client_context_t * p_client = NULL;

err_code = blcm_link_ctx_get(p_nus->p_link_ctx_storage, p_ble_evt->evt.gap_evt.conn_handle, (void *) &p_client);

ret_code_t blcm_link_ctx_get(blcm_link_ctx_storage_t const * const p_link_ctx_storage, uint16_t const conn_handle, void ** const pp_ctx_data)

Using CPP static_cast, reinterpret_cast. I expect to build ble_nus.c


Solution

  • &p_client is a pointer to a pointer (two-levels).

    You cast a pointer to a pointer (two-levels) to a (one-level) pointer.

    If you remove the casting of the last parameter, it should work just fine.

    Like:

    ble_nus_client_context_t * p_client = NULL;
    err_code = blcm_link_ctx_get(p_nus->p_link_ctx_storage, p_ble_evt->evt.gap_evt.conn_handle, &p_client);
    

    Another option is to cast to void** as expected.

    ble_nus_client_context_t * p_client = NULL;
    err_code = blcm_link_ctx_get(p_nus->p_link_ctx_storage, p_ble_evt->evt.gap_evt.conn_handle, (void**)&p_client);