From: Junio C Hamano Date: Fri, 06 Nov 2026 19:36:02 GMT Subject: Re: [PATCH] repo: zero-initialize configuration values Message-ID: In-Reply-To: Patrick Steinhardt writes: > In any case, the patch is obviously correct and is a good improvement in > my opinion. So this looks good to me, thanks. It however does not look good to me. I would prefer to see struct foo foo = {0}; if everything is zero initialized, or if there are some members initialized to specific values, C99 designated initializers to be used: struct foo foo = { /* Comment on this stuff */ .object_creation_mode = OBJECT_CREATION_MODE, /* Comment on this other stuff */ .branch_track = BRANCH_TRACK_REMOTE, }; Now this is overwriting the passed in structure members, so how we write the initialization is not the whole story. Since we have avoided assuming the universal availability of the more recent "compound literals" syntax, which is: *cfg = (struct foo) { ... an initialization with designated initializers ... }; we seem to (ab)use struct assignment, e.g., static struct foo foo_template = { ... an initialization with designated initializers ... }; *cfg = foo_template; in a few places as a fallback in the existing code (DI is C99, struct assignment is C89, so it has been a safer assumption than assuming compound literals). But I do recall we made this update to our CodingGuidelines document. . since late 2024 with v2.48.0-rc0~20, we have been using compound literals, e.g., (struct foo){ .member = value }; So perhaps it is time to switch this to assign a compound literal?