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

Re: [PATCH] range-diff: fix some 'hdr-check' and sparse warnings

From
Jeff King <peff@peff.net>
Date
Jul 15, 2019, 14:46 UTC
Message-ID
<20190715144602.GA26636@sigill.intra.peff.net>
In-Reply-To
<54c2ee44-ee99-ea4a-3154-f642e0060877@kdbg.org>
On Sun, Jul 14, 2019 at 10:30:27AM +0200, Johannes Sixt wrote:
> Why would you re-order members? There's nothing wrong when a pointer is
> initialized by 0.

To appease tooling like "sparse" without having to remember to do anything specific at the point-of-use sites. I'm open to the idea that it is not worth appeasing sparse, but this may be a simple and practical compromise.

Show 6 quoted lines
> > But it does fall down
> > when the first element _has_ to be a struct (like, say, any user of our
> > hashmap.[ch] interface).
> 
> No, it does not. It is not necessary to spell out nested structs in the
> initializer.

Ah, that is news to me. I know that this compiles OK with "gcc -Wall", but is it guaranteed by the standard?

-- >8 -- #include <stdio.h>

struct outer {
	struct {
		int x;
		char *y;
	} inner;
};
int main(void)
{
	struct outer foo = { 0 };
	printf("%d %p\n", foo.inner.x, foo.inner.y);
	return 0;
}
-- 8< --

If so, then I agree that "0" is a pretty good solution, tooling like "sparse" aside. I do agree with your sentiment that "0" can be read as "please zero-initialize this struct" and not really as an attempt to set an initial member pointer to zero.

-Peff
Previous: Johannes SixtNext: Johannes Sixt
Message 11 of 23 in “range-diff: fix some 'hdr-check' and sparse warnings”
  1. range-diff: fix some 'hdr-check' and sparse warningsRamsay Jones, Jul 11, 2019
  2. Johannes SixtJul 12, 2019
  3. Junio C HamanoJul 12, 2019
  4. Johannes SixtJul 13, 2019
  5. Johannes SixtJul 13, 2019
  6. Carlo ArenasJul 13, 2019
  7. Junio C HamanoJul 13, 2019
  8. Carlo ArenasJul 13, 2019
  9. Jeff KingJul 14, 2019
  10. Johannes SixtJul 14, 2019
  11. Jeff KingJul 15, 2019
  12. Johannes SixtJul 15, 2019
  13. Jeff KingJul 15, 2019
  14. Junio C HamanoJul 16, 2019
  15. Jeff KingJul 16, 2019
  16. Junio C HamanoJul 17, 2019
  17. Jeff KingJul 17, 2019
  18. Junio C HamanoJul 17, 2019
  19. Johannes SixtJul 17, 2019
  20. Johannes SchindelinJul 15, 2019
  21. Junio C HamanoOct 2, 2020
  22. Johannes SchindelinOct 4, 2020
  23. Johannes SixtJul 14, 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.