Philippe:
On Thu, May 14, 2020 at 9:36 PM Philippe Verdy <verdyp@gmail.com> wrote:
> Le mer. 13 mai 2020 à 19:20, Massimo Sala <massimo.sala.71@gmail.com> a écrit :
>> I consider this article, written by Gnu C authors, enlightening on the topic:
>> https://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html
> I have to disagree to this statement made in that article: "Although the size of a zero-length array is zero, an array member of this kind may increase the size of the enclosing type as a result of tail padding."
That was expected.
Have you ever worked
Yes of course !!!
with an architecture needing alignment, or
considered the zero length array does not need to be of a trivially
aligned type like char, i.e., how about { char a; int b[] }?
Yes, not a problem, the "char a" has no alignment constraints: sizeof(a)=1 and alignof(a) =1
But given that for example sizeof(int)=4 and alignof(int)=4 mayu be needed with some platform, b will be prepadded. with 3 bytes. The total structure has then 8 bytes, not 5
Nother is **appended**. We're just speaking about *prepending* for aligning additional fields in order to satisfy their own type constraints or performance needed to access invidual fields.
> Because I don't see which kind of tail padding would occur after a zero-length array (which does not change at all the size of existing enclosing type, except for aligning the first member of the zero-length array: this is not *trailing* padding, but *leading* padding,
So, you knew it. Classic. First you disagree to a thing, the you
DEFINE another. Then you prove your definition matches itself.
I'm not defining anything....
What about double[0] on a cray?
Does not matter if it's a double or int or long double or the plaform. What matters is what is PREPENDED before this array to satisfy the need for the new type, and only this type.
With char([0] you'r concernend by what is prepended to satisfy the need of a single "char", but a char is always aligned at any position: sizeof(char)==alignof(char)==1.
> As a consequence, I do not see any difference of the size and alignment of the enclosing type if it is terminated by an trailing char[0] member or if this member is absent.
Here is the catch. The article speaks about zero length arrays, you
rant about zero length char arrays.
No you just "rant" about me by incorrectly assuming false understanding of the supposed problem.
I assert that we are NOT concerned by what is appended, but only what is prepended. And using char[1] or char[0] will not change the position of the first item which is never prepended with anything (except trailing unused bits to fill bytes but left unused by previous bitfields, but hzere again this makes no difference, these trailing bits exist for any other type you add after it except if the other added member is also a bitfield a "char" along however is not a bitfield).