Re: [PATCH] git-compat-util(msvc): C11 does not imply support for zero-sized arrays

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Phillip Wood <phillip.wood123@xxxxxxxxx> writes:

>> the end of a struct isn't triggering a compile error. But having a field
>> _after_ that empty flex array _does_ trigger a compile error:
>> struct MyStruct {
>>      int x;
>>      int flexA[];
>>      char string[256];
>> };
>> Note the added `string` field.

Ick.

If we use the "safer but a bit wasteful" alternative in such a case,
it will become just wrong.  We'll have a single-member array there,
and extra allocation for an instance of MyStruct will only lengthen
the .string member, without allowing the .flexA member to have more
elements.

> Having a field after the flex array is a violation of the C
> standard. Section 6.7.2.1:
>    ... the last member of a structure with more than one named member
>    may have incomplete array type, such a structure (and any union
>    containing, possibly recursively, a member that is such a structure)
>    shall not be a member of a structure or an element of an array.
>
> Note that the wording also forbids
>
> struct A {
> 	int x;
> 	char flex[];
> };
>
> struct B {
> 	struct A a; /* This is forbidden */
> };
>
> There was a proposal a few years ago to relax that restriction [1] but
> it does not seem to be in the latest draft standard.
>
> None of this helps fix the problem, but it does explain why MSVC complains.

Thanks.

In short, the code is wrong, and the compiler is complaining to
avoid us using a wrong code.  If the same code is given to other
compilers that support ANCI C style flexible array member, we are
likely to see the same error.

Which makes the whole thing (including my "let's make the
conditionals to set up FLEX_ARRAY for various compilers easier to
read") much less urgent.

Thanks for a well-written summary.




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux