Deutsch   English   Français   Italiano  
<875xjascwp.fsf@nosuchdomain.example.com>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!eternal-september.org!.POSTED!not-for-mail
From: Keith Thompson <Keith.S.Thompson+u@gmail.com>
Newsgroups: comp.lang.c
Subject: Re: sizeof struct with flexible array: when did it change?
Date: Fri, 11 Apr 2025 12:42:30 -0700
Organization: None to speak of
Lines: 57
Message-ID: <875xjascwp.fsf@nosuchdomain.example.com>
References: <20241006192337.76@kylheku.com> <20250410200202.357@kylheku.com>
	<86bjt2c3sj.fsf@linuxsc.com>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Date: Fri, 11 Apr 2025 21:42:32 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="c7132c9dc01e9da84b004e8ef39b7407";
	logging-data="2384762"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX18Iq7ShpBqjJuk/lPnl0vwR"
User-Agent: Gnus/5.13 (Gnus v5.13)
Cancel-Lock: sha1:BYzrfqVC4uSHi3GlKO1UJjfriaA=
	sha1:26GLSht4CQks+vmns+tMqe7CM+Q=
Bytes: 3298

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.com
void Void(void) { Void(); } /* The recursive call of the void */