Sujet : Re: sizeof struct with flexible array: when did it change?
De : Keith.S.Thompson+u (at) *nospam* gmail.com (Keith Thompson)
Groupes : comp.lang.cDate : 11. Apr 2025, 20:42:30
Autres entêtes
Organisation : None to speak of
Message-ID : <875xjascwp.fsf@nosuchdomain.example.com>
References : 1 2 3
User-Agent : Gnus/5.13 (Gnus v5.13)
Tim Rentsch <
tr.17687@z991.linuxsc.com> writes:
Kaz Kylheku <643-408-1753@kylheku.com> writes:
>
On 2024-10-07, Kaz Kylheku <643-408-1753@kylheku.com> wrote:
>
C99 said that the size of a structure that ends in a flexible array
member is the same as the offset of that flexible member in a
similar structure in which the array has some unspecified size.
>
The latest draft says that the size is calculated as if the flexible
array member were omitted, except that there may be more padding than
the omission would imply.
>
I just noticed that a draft version of C99 has exactly this
same wording!
>
I am skeptical. Which document is that exactly?
The C99 standard (6.7.2.1p16) says:
First, the size of the structure shall be equal to the offset
of the last element of an otherwise identical structure that
replaces the flexible array member with an array of unspecified
length.
with a footnote:
The length is unspecified to allow for the fact that implementations
may give array members different alignments according to their
lengths.
The N1256 draft, which incorporates the C99 standard with the three
Technical Corrigenda, says:
In particular, the size of the structure is as if the flexible
array member were omitted except that it may have more trailing
padding than the omission would imply.
with change bars. The same wording is in the latest C2y draft, and
presumably in all editions and drafts after N1256 (I haven't checked).
The change was made in response to DR #282,
<
https://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_282.htm>.
The summary of that DR says:
6.7.2.1 Structure and union specifiers, paragraphs 15 and 16
require that any padding for alignment of a structure containing
a flexible array member must preceed the flexible array member.
This contradicts existing implementations. We do not believe
this was the intent of the C99 specification.
Assuming N1256 is the draft Kaz was referring to, there was no
backpedaling. N1256 is newer than the published C99 standard.
-- Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.comvoid Void(void) { Void(); } /* The recursive call of the void */