Thread (27 messages) 27 messages, 7 authors, 2021-09-30

Re: [PATCH v2 2/5] *.[ch] *_INIT macros: use { 0 } for a "zero out" idiom

flat view

From: Ramsay Jones <hidden>
Date: 2021-09-28 01:44:44


On 28/09/2021 01:25, Ævar Arnfjörð Bjarmason wrote:
On Mon, Sep 27 2021, Jeff King wrote:
quoted
On Mon, Sep 27, 2021 at 02:54:25PM +0200, Ævar Arnfjörð Bjarmason wrote:
quoted
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/ (local)

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.
[+CC Luc Van Oostenryck [off-list ref]]

It seems like we should just revert 1c96642326, looking at the history
of sparse.git there's:

 - 537e3e2d (univ-init: conditionally accept { 0 } without warnings, 2020-05-18)

Followed by git.git's 1c96642326 a few days later, but then in sparse.git:

 - 41f651b4 (univ-init: set default to -Wno-universal-initializer, 2020-05-29)

I.e. a few days after the workaround in git.git the upstream repo
changed the default. The 537e3e2d isn't in any release of sparse that
41f651b4 isn't in, they both first appeared in v0.6.2.

So us having -Wno-universal-initializer only seems useful if you're
using some old commit in sparse.git.

Having written the above I found
https://lore.kernel.org/git/20200530162432.a7fitzjc53hsn2ej@ltop.local/ (local);
i.e. sparse's maintainer pretty much saying the same thing.
Yes, this has been on my TODO list pretty much since commit 41f651b4, but
it wasn't a priority. ;-)

ATB,
Ramsay Jones
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help