Path: csiph.com!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!eternal-september.org!.POSTED!not-for-mail From: Tim Rentsch Newsgroups: comp.lang.c Subject: Re: sizeof struct with flexible array: when did it change? Date: Fri, 11 Apr 2025 13:34:24 -0700 Organization: A noiseless patient Spider Lines: 75 Message-ID: <86mscma14f.fsf@linuxsc.com> References: <20241006192337.76@kylheku.com> <20250410200202.357@kylheku.com> <86bjt2c3sj.fsf@linuxsc.com> <875xjascwp.fsf@nosuchdomain.example.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Date: Fri, 11 Apr 2025 22:34:25 +0200 (CEST) Injection-Info: dont-email.me; posting-host="71ab0539a1cf710e3caa6c34edacc1d7"; logging-data="2652245"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/LuDRjz6mn+u59ayWMtFeQCBR3bOcRf8U=" User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux) Cancel-Lock: sha1:a5cWJB963Bk6lEJlPPAySNfb3NM= sha1:4x66niYVIafSkJqP3/nKkleyeFk= Xref: csiph.com comp.lang.c:392415 Keith Thompson writes: > Tim Rentsch 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, > . > 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.