Subject: Re: [PATCH 02/11] submodule--helper: replace memset() with { 0 }-initialization

From: Junio C Hamano <[email-masked]>
Date: Wed, 13 Jul 2022 14:19:11 -0700

Glen Choo <[email-masked]> writes:

> 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.