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:23:41 -0700 Organization: A noiseless patient Spider Lines: 28 Message-ID: <86cxz1pgiq.fsf@linuxsc.com> References: <10tqqso$kn23$1@dont-email.me> <86jytar6n2.fsf@linuxsc.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Date: Tue, 12 May 2026 01:23:44 +0000 (UTC) Injection-Info: dont-email.me; logging-data="1654897"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/aJ0eEgKCaKaLTOS2f4DJWzfZjxJyVso0="; posting-host="714746643ff61f997ea29d517f63563d" User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux) Cancel-Lock: sha1:Nu0wFPrYA5qiNyWh7+xInc9qFEM= sha1:/IqgJTm23fjNRx8RShKojJeX/5Q= sha256:OE276fU+1W0yH29DGpQ3e6KsivEThwNu3pHy85dx+ek= sha1:S8nsfmNo+mbpziTaici88nCtZ+w= Xref: csiph.com comp.lang.c:398790 scott@slp53.sl.home (Scott Lurndal) writes: > Tim Rentsch writes: > >> highcrew writes: >> >>> Hello, >>> > >> >> Point 3: if you want to initialize and zero a struct, along with >> elements of a non-trivial flexible array member, probably the best >> way to do that is as part of a union with an array of unsigned char, >> for example as follows: >> >> union { >> unsigned char uca[ SUITABLE_SIZE ]; >> struct array fam; >> } blah = { .uca = { 0 } }; >> >> struct array *stuff = &blah.fam; > > Or use memset(3) with the appropriate length. Part of the motivation of using a declarative and functional formulation is being able to use it in an expressional, rather than imperative, context. The code shown above can be used at file scope, which precludes the use of memset().