Re: [PATCH 02/11] submodule--helper: replace memset() with { 0 }-initialization
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Jul 13, 2022, 21:19 UTC
- Message-ID
- <xmqqy1wwaey8.fsf@gitster.g>
- In-Reply-To
- <kl6lfsj4684n.fsf@chooglen-macbookpro.roam.corp.google.com>
Glen Choo <chooglen@google.com> writes:
Show 5 quoted lines
> Ok. I wonder if we could reduce this kind of churn in the future by
> adding this to CodingGuidelines, e.g. "always use { 0 } for stack
> variables". Tangentially, do we require { NULL } when the first element
> is a pointer? (I'm not sure because this isn't in CodingGuidelines
> either AFAICT.)A valiable can legitimately be left uninitialized, or initialized to a known value that is not zero using designated initializers. So saying something like
When zero-initializing an auto variable that is a struct or
union in its definition, use "{ 0 }", whether the first member
in the struct is of a number, a pointer, or a compound type.may be OK. I do not think we would want to say "always use X", as the world is not that simple..
We do favor designated initializers over traditional initialization in the order of members these days, so something like
When declaring a struct/union variable or an array with initial
value to some members or elements, consider using designated
initializers, instead of listing the values in the order of
members in the definition of the struct.would also be good.
Thanks.