Re: [PATCH v2 2/5] *.[ch] *_INIT macros: use { 0 } for a "zero out" idiom
- From
Jeff King <peff@peff.net>
- Date
- Sep 27, 2021, 23:24 UTC
- Message-ID
- <YVJSwuqjolz28+mG@coredump.intra.peff.net>
- In-Reply-To
- <patch-v2-2.5-afcd2729c95-20210927T124407Z-avarab@gmail.com>
On Mon, Sep 27, 2021 at 02:54:25PM +0200, Ævar Arnfjörð Bjarmason wrote:
Show 10 quoted lines
> In C it isn't required to specify that all members of a struct are
> zero'd out to 0, NULL or '\0', just providing a "{ 0 }" will
> accomplish that.
>
> Let's also change code that provided N zero'd fields to just
> provide one, and change e.g. "{ NULL }" to "{ 0 }" for
> consistency. I.e. even if the first member is a pointer let's use "0"
> instead of "NULL". The point of using "0" consistently is to pick one,
> and to not have the reader wonder why we're not using the same pattern
> everywhere.I seem to recall we've had some linter complaints about using "0" to initialize a pointer, but I think these days it's OK, per:
- 1c96642326 (sparse: allow '{ 0 }' to be used without warnings,
2020-05-22)and
- https://lore.kernel.org/git/18bd6127-be72-b7b7-8e2a-17bbe7214a2e@ramsayjones.plus.com/
I think this is a good step, as the long lists are unwieldy and difficult to keep up to date without actually providing any readability or functional value.
-Peff