Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nrf_rpc: fix build error for C++ #1514

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Damian-Nordic
Copy link
Contributor

In C++, conversion from a function pointer to void* is either undefined (prior to C++11) or not implicit.

Replace the cast from a function pointer to (void*) with a cast to (uintptr_t) to fix build errors when including nrf_rpc.h in C++ applications.

In C++, conversion from a function pointer to void* is
either undefined (prior to C++11) or not implicit.

Replace the cast from a function pointer to (void*) with
a cast to (uintptr_t) to fix build errors when including
nrf_rpc.h in C++ applications.

Signed-off-by: Damian Krolik <[email protected]>
@alxelax
Copy link
Contributor

alxelax commented Oct 10, 2024

Why is C code built by C++ compiler?

@Damian-Nordic
Copy link
Contributor Author

Why is C code built by C++ compiler?

Because Matter firmware needs to include nrf_rpc.h (to call nrf_rpc_init), which includes the c++-prohibited casts.

@alxelax
Copy link
Contributor

alxelax commented Oct 10, 2024

Why is C code built by C++ compiler?

Because Matter firmware needs to include nrf_rpc.h (to call nrf_rpc_init), which includes the c++-prohibited casts.

I do not think that inline functions are a correct implementation for headers, which are used in both C and C++.
I see problem not in void * usage in general, but in inlining of C code within C++ without explicit letting know about that to compiler.

I do not like forced typecasting since it might dig in deep the type mismatching. Would it be more meaningful to move inline functions into C file and remove inline modificator?

@Damian-Nordic
Copy link
Contributor Author

I do not think that inline functions are a correct implementation for headers, which are used in both C and C++. I see problem not in void * usage in general, but in inlining of C code within C++ without explicit letting know about that to compiler.

I do not like forced typecasting since it might dig in deep the type mismatching. Would it be more meaningful to move inline functions into C file and remove inline modificator?

As long as the inline functions don't use any C-only features like compound literals, there's no issue with that, no?

Moving the functions to C file will not remove the casts. To make it 100% type-safe I would probably need to duplicate some code, which contradicts the authors' intention to optimize the code size of this fragment.

@alxelax
Copy link
Contributor

alxelax commented Oct 11, 2024

Discussed IRL. Let it be but for future to be accurate with potential miscasting in such functions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants