Groups | Search | Server Info | Login | Register


Groups > comp.lang.c > #392415

Re: sizeof struct with flexible array: when did it change?

From Tim Rentsch <tr.17687@z991.linuxsc.com>
Newsgroups comp.lang.c
Subject Re: sizeof struct with flexible array: when did it change?
Date 2025-04-11 13:34 -0700
Organization A noiseless patient Spider
Message-ID <86mscma14f.fsf@linuxsc.com> (permalink)
References <20241006192337.76@kylheku.com> <20250410200202.357@kylheku.com> <86bjt2c3sj.fsf@linuxsc.com> <875xjascwp.fsf@nosuchdomain.example.com>

Show all headers | View raw


Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:

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

Yes, I know all that.  I have the impression Kaz meant to allege
that there was a draft done prior to the original C99 standard,
where said draft had wording matching the wording in N1256.  As
far as I can tell no such draft exists, and that's why I asked
the question I did.

> Assuming N1256 is the draft Kaz was referring to, there was no
> backpedaling.  N1256 is newer than the published C99 standard.

Right, I knew that too.  It's because Kaz used the word backpedaled
(unfortunately in a paragraph I removed from my response) that I
asked the question.  Here is that paragraph, restored (with an
appropriate attribution, assuming I have copy/pasted correctly):

>> Kaz Kylheku <643-408-1753@kylheku.com> writes:
>>
>>> In other words, C99 changed it prior to publication, and then it
>>> was backpedaled to the C99 draft text, and that remains current.

That paragraph was at the end of the post to which I was
originally responding.

Back to comp.lang.c | Previous | NextPrevious in thread | Find similar


Thread

Re: sizeof struct with flexible array: when did it change? Kaz Kylheku <643-408-1753@kylheku.com> - 2025-04-11 03:04 +0000
  Re: sizeof struct with flexible array: when did it change? Tim Rentsch <tr.17687@z991.linuxsc.com> - 2025-04-11 04:53 -0700
    Re: sizeof struct with flexible array: when did it change? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2025-04-11 12:42 -0700
      Re: sizeof struct with flexible array: when did it change? Tim Rentsch <tr.17687@z991.linuxsc.com> - 2025-04-11 13:34 -0700

csiph-web