RĂ©mi Bernon rbernon@codeweavers.com writes:
On 3/23/22 14:05, Eric Pouech wrote:
Well I think this makes the code very bloated, and if it is truly UB then we should instead find a way to use 0-sized arrays in a portable way.
I believe 0 sized array for the last struct member is standard C99, so is there any compiler not supporting it yet (or some variation of it like with empty size)?
yes the so called "flexible array member" is c99 and seems to be supported by gcc, clang, msvc but they don't seem to be accepted directly into wine (for now) (for example include/winnt.h see https://source.winehq.org/source/include/winnt.h#5815) (there are a few others instances in the same way)
there are a couple of 0-length array instances (mosts of them protected by #ifdef _GNUC and fallback with 1 length array) (and wine/msvcpdb.h uses them directly w/o fallbacks...)
I did a previous attempt with 0 length array for this but it never landed (https://www.winehq.org/pipermail/wine-devel/2022-February/207793.html)
so I'd wait for Alexandre's guidance on this A+
C99 flexible array is with empty size, not 0.
From https://gcc.godbolt.org/z/nc6xGM5nh I don't see any compiler not supporting even both methods, though -pedantic emits a warning with 0 size (empty size is fine).
It only tests some old GCC / Clang version as they don't provide old MSVC but maybe it's okay?
An empty size is probably OK to use at this point. It's not clear how much benefit it brings though, because obviously 1-size arrays in public structures can't be changed.