Path: csiph.com!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: UB or not UB? was: On Undefined Behavior Date: Thu, 15 Jan 2026 04:04:05 -0800 Organization: None to speak of Lines: 28 Message-ID: <87ikd3nkui.fsf@example.invalid> References: <10j6qdt$3q9n4$1@dont-email.me> <20260112162857.00003dd8@yahoo.com> <10k35mn$2ean4$1@dont-email.me> <20260112200821.000020a5@yahoo.com> <10k71vr$15aeb$11@dont-email.me> <10k7kga$3q0mm$2@dont-email.me> <87y0lzolxf.fsf@example.invalid> <10kagfd$n920$1@dont-email.me> MIME-Version: 1.0 Content-Type: text/plain Injection-Date: Thu, 15 Jan 2026 12:04:06 +0000 (UTC) Injection-Info: dont-email.me; posting-host="4d7fe61be3b508b2d5a980eafedcef32"; logging-data="802666"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19zSfo5iponiWcrjjsmRBvs" User-Agent: Gnus/5.13 (Gnus v5.13) Cancel-Lock: sha1:1sUFrWOyojnAN/7hqKTCWWkpVsU= sha1:N2zRWoESG0Sbf3jLxXUjzUL1fso= Xref: csiph.com comp.lang.c:396431 David Brown writes: > On 14/01/2026 23:43, Keith Thompson wrote: [...] >> There can be arbitrary padding between struct members, or after the >> last member. Almost(?) all implementations add padding only to >> satisfy alignment requirements, but the standard doesn't state any >> restrictions. There can be no padding before the first member, and >> offsets of members must be increasing. > > On closer reading, I agree with you here. I find it a little > surprising that this is not implementation-defined. If an > implementation can arbitrarily add extra padding within a struct, it > severely limits the use of structs in contexts outside the current > translation unit. In practice, struct layouts are (I think) typically specified by a system's ABI, and ABIs generally permit/require only whatever padding is necessary to meet alignment requirements. And I think C has rules about type compatibility that are intended to cover the same struct definition being used in different translation units within a program, though I'm too lazy to look up the details. [...] -- Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com void Void(void) { Void(); } /* The recursive call of the void */