0

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

7
  • p_client is already a pointer. When you takes it address, e.g. &p_client the type is ble_nus_client_context_t**. Your cast with (void *) &p_client is casting to void* (legal in C), not ble_nus_client_context_t** - so you must account for the additional level of indirection when you cast back from void*. Commented Dec 26, 2023 at 9:09
  • @DavidC.Rankin Is it not ble_nus_client_context_t**? Or is that an alias? Commented Dec 26, 2023 at 9:10
  • 4
    @PasserBy - yes, sorry, but the additional level of indirection holds. This is made a bit more troubling by the mixing of C++ and ble_nus.c. Please provide A Minimal Complete Reproducable Example to help clear up the confusion. Commented Dec 26, 2023 at 9:12
  • 3
    Why are you trying to compile c code with a c++ compiler? Why not just use a c compiler, they're separate languages, c++ isn't a superset of c Commented Dec 26, 2023 at 9:49
  • 2
    Why not show us a snippet of code that will reproduce the error so that we don't have to guess? Commented Dec 26, 2023 at 9:51

1 Answer 1

0

&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);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.