eclipse-threadx / usbx

Eclipse ThreadX - USBX is a high-performance USB host, device, and on-the-go (OTG) embedded stack, that is fully integrated with Eclipse ThreadX RTOS
https://github.com/eclipse-threadx/rtos-docs/blob/main/rtos-docs/usbx/index.md
MIT License
148 stars 88 forks source link

Provide a C++ compatible macro definition for UX_NULL #97

Open aerisnju opened 1 year ago

aerisnju commented 1 year ago

We have a macro stands for null pointers. i.e. UX_NULL. Currently its definition is

#define UX_NULL                                                         ((void*)0)

It works perfectly for C projects. But when it comes to C++, we will get compilation errors because ((void*)0) is not allowed in C++ as a null pointer [1]. Instead, 0 or nullptr are allowed. So we need to change the macro definition in C++.

In the PR I use the presence of macro __cplusplus to distinguish C and C++ environments. We will still get the original definitions when we compile C sources. For maximum compability, I choose to use 0 as the definition instead of nullptr because the latter requires c++11 or later.

[1] https://en.cppreference.com/w/cpp/types/NULL