git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 00/52] fix some -Wmissing-field-initializer warnings

From
Johannes Sixt <j6t@kdbg.org>
Date
May 30, 2019, 08:47 UTC
Message-ID
<0f1c5a49-f971-848d-700e-9c124ae8e617@kdbg.org>
In-Reply-To
<cf0b720e-ad29-79e7-17d5-b69d50e7007e@ramsayjones.plus.com>
Hi Ramsay,

I had a brief look at the series. IMO, it is a mistake to appease -Wmissing-field-initializer.

We have two sorts of initializers:
 - zero initializers: they just want to null out every field,
   like CHILD_PROCESS_INIT and ad-hoc initializers of structs
   such as xpparam_t pp = { 0 }; in range-diff.c
 - value initializers are always macros, such as STRING_LIST_INIT_DUP
   and the OPT_* family.

I am strongly against forcing zero initializers to write down a value for every field. It is much more preferable to depend on that the compiler does the right thing with them. -Wmissing-field-initializer would provide guidance in the wrong direction. A zero initializer looks like this: = { 0 }; and nothing else.

(And for this reason, I also think it is wrong to change 0 to NULL in initializers to appease sparse's "zero used as pointer value" warning. Let the compiler do the right thing.)

Value initializers are a different matter. The changes you have prepared around struct option initializers are good, IMO. Whether or not you add trailing zeros to the macros makes no difference for the users of the macros.

-- Hannes
Previous: Ramsay JonesNext: Jeff King
Message 4 of 6 in “fix some -Wmissing-field-initializer warnings”
  1. 00/52 fix some -Wmissing-field-initializer warningsRamsay Jones, May 24, 2019
  2. Ævar Arnfjörð BjarmasonMay 24, 2019
  3. Ramsay JonesMay 24, 2019
  4. Johannes SixtMay 30, 2019
  5. Jeff KingMay 30, 2019
  6. Ramsay JonesMay 30, 2019

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.