Path: csiph.com!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail From: Tim Rentsch Newsgroups: comp.lang.c Subject: Re: Are designated initializer supposed to zero padding? Date: Mon, 11 May 2026 18:13:41 -0700 Organization: A noiseless patient Spider Lines: 54 Message-ID: <86lddppgze.fsf@linuxsc.com> References: <10tqqso$kn23$1@dont-email.me> <86jytar6n2.fsf@linuxsc.com> <20260511232247.00006c5e@yahoo.com> <86wlx9pp10.fsf@linuxsc.com> <10ttnl3$1g54p$2@kst.eternal-september.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Date: Tue, 12 May 2026 01:13:44 +0000 (UTC) Injection-Info: dont-email.me; logging-data="1654897"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18l4VAI7LVkqaRG0xskehcYfUfneJhPH/I="; posting-host="714746643ff61f997ea29d517f63563d" User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux) Cancel-Lock: sha1:EB3A1ZVCsD7zXYMETMM5SnXnB3o= sha1:mPnozfjk/68O6cJUgSogYL+Y4b4= sha256:EHM5I7jl1x8g6d7LqbBNPEzU4SslwPt+pBam5A6UJ+M= sha1:XeIoUuhiZgXgdkm7mCF8E4hrTyU= Xref: csiph.com comp.lang.c:398788 Keith Thompson writes: > Tim Rentsch writes: > >> Michael S writes: >> >>> On Sun, 10 May 2026 20:01:53 -0700 >>> Tim Rentsch wrote: >>> >>>> Point 1: initializers are not required to set padding (either >>>> padding bits or padding bytes). Don't expect padding to be >>>> zeroed. This statement applies to initializers in all forms - >>>> regular initializers, designated initializers, and compound >>>> literals. >>> >>> James Kuyper says that zeroing of padding is required by that standard. >>> I am not an expert in lawyer-style reading of the standard, but at my >>> level it looks that he is correct and the wording in unequivocal. >>> For example, n3220, 6.7.11: >>> >>> 11 >>> If an object that has automatic storage duration is not initialized >>> explicitly, its representation is indeterminate. If an object that has >>> static or thread storage duration is not initialized explicitly, or >>> any object is initialized with an empty initializer, then it is subject >>> to default initialization, which initializes an object as follows: >>> ? if it has pointer type, it is initialized to a null pointer; >>> ? if it has decimal floating type, it is initialized to positive zero, >>> and the quantum exponent is implementation-defined; >>> ? if it has arithmetic type, and it does not have decimal floating >>> type, it is initialized to (positive or unsigned) zero; >>> ? if it is an aggregate, every member is initialized (recursively) >>> according to these rules, and any padding is initialized to zero bits; >> >> The problem is padding is none of those things. > > Um, padding is padding. "... and any padding is initialized to zero > bits". Sorry, I stand corrected. It looks like this change was made as part of C11. So in C99 padding is not initialized to zeros, and in C11 and later it is. > As I wrote elsethread, it seems clear that padding within subobjects > (except for automatic objects with no initializer) is set to zero bits. > I haven't found wording that applies that to top-level padding. What does it mean to talk about top-level padding? Isn't it the case that padding (not counting padding bits in arithmetic types) occurs only in structs and unions? Can you give an example of a declaration where "top-level padding" occurs? I should add that I haven't yet read the other post where you talk about this.