Path: csiph.com!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail From: John Ames Newsgroups: comp.os.linux.misc,alt.folklore.computers Subject: Re: C structures, was naughty Python Date: Fri, 2 Jan 2026 15:44:23 -0800 Organization: A noiseless patient Spider Lines: 22 Message-ID: <20260102154423.00005133@gmail.com> References: <10j88fb$at2l$2@dont-email.me> <20260102084925.000040b5@gmail.com> <10j9dis$mp8i$15@dont-email.me> <10j9hj6$63p$3@gal.iecc.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Date: Fri, 02 Jan 2026 23:44:26 +0000 (UTC) Injection-Info: dont-email.me; posting-host="1835d86fa916216d0804243b2e2c589b"; logging-data="890024"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+Bpn4Oe5P9TEf6Ek4OCBQ60EHPm8LoRCc=" Cancel-Lock: sha1:VVvjqK6Gvumra2yPSXd150Lm+qU= X-Newsreader: Claws Mail 4.3.0 (GTK 3.24.42; x86_64-w64-mingw32) Xref: csiph.com comp.os.linux.misc:80366 alt.folklore.computers:233092 On Fri, 2 Jan 2026 22:41:42 -0000 (UTC) John Levine wrote: > >> ... it's not guaranteed that the compiler won't take liberties in > >> arranging members of a struct for optimization purposes ... =20 > > > >The C23 spec (section 6.2.5, =E2=80=9CTypes=E2=80=9D) does say the membe= r objects of > >a struct type need to be =E2=80=9Csequentially allocated=E2=80=9D. =20 >=20 > That language has been there a long time. It's in my copy of C11 and > it wasn't new then. It's probably always been there since we wrote > code that used the common struct prefix hack in K&R C. I went to check and, lo, it's in the C89 spec as well; as was already indicated by Lawrence, I must've been thinking of compilers inserting padding for alignment purposes. Which does raise the same basic concern (the block of memory allocated to a struct is not *necessarily* a 1:1 concatenation of its members, and casting pointers between different data structures should be done with caution,) but my recollection was evidently in need of clarification.