From: Joie Joie Date: Mon, 09 Nov 2026 14:26:22 GMT Subject: Re: [PATCH] repo: zero-initialize configuration values Message-ID: In-Reply-To: Thanks, Junio. I hadn't considered using a compound literal here. I was following the existing initialization approach, but your suggestion makes sense, especially given the update to the CodingGuidelines. I'll look into changing the initialization to use a compound literal while preserving the existing defaults and behavior. On Fri, Nov 6, 2026 at 8:36 PM Junio C Hamano wrote: > > 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?