libusb_stm32 icon indicating copy to clipboard operation
libusb_stm32 copied to clipboard

[Discussion] C++ compilers really hate flexible array member.

Open apricot-azumi opened this issue 7 months ago • 1 comments

C++ compilers really hate struct {...; char vla[];};. It gives warning for many struct declarations, which can be fortunately suppressed with:

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wpedantic"
#include <usb.h>
#pragma GCC diagnostic pop

But USB_ARRAY_DESC and USB_STRING_DESC_CXX fails with no rescue.

One workaround is to use this in another C file, and use extern "C" in c++. LTO gives warning about type mismatch between units.

I personally use this https://godbolt.org/z/aTG1aEP96 in my project. This looks somewhat overkill and it requires C++17/20.

What's your opinion on compatibility with C++?

apricot-azumi avatar Jul 22 '24 18:07 apricot-azumi