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

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

Open
apricot-azumi opened this issue Jul 22, 2024 · 1 comment
Open

Comments

@apricot-azumi
Copy link

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++?

@dmitrystu
Copy link
Owner

dmitrystu commented Jul 22, 2024

Unfortunately, there are a lot of flexible arrays in the USB by design. I don't have much experience with pluses, but I think it would be a good idea to place all descriptors and the descriptor handling callback into a separate C file, compile it using C to object, and let the linker do its job.
P.S. USB_ARRAY_DESC and USB_STRING_DESC are just helper macros. All descriptors are just byte arrays, usually located in the .rodata section. I don't see how the linker might try to optimize this.

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

No branches or pull requests

2 participants