lua-users home
lua-l archive

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


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 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[] }?

> 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.e. influences the offset of the 1st element that could be in the
variable-size array; but when the zero-length array has base type
"char", its alignment is 1 by definition, meaning that multiple
members of type non-array char are just packed at successive
offsets+1:

> In contrast, a compiler that sees a "char[4]" member declaration may know that this member has a size which is at least 4 bytes, and may opt to align the whole array so its first element will be aligned to a 32-bit boundary. But a "char[0]" has a sizeof zero: you can align it to any multiple of a byte/word boundary, it will remain zero.

What about  double[0] on a cray?

> 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.

Francisco Olarte.
_______________________________________________
lua-l mailing list -- lua-l@lists.lua.org
To unsubscribe send an email to lua-l-leave@lists.lua.org