Junio C Hamano <gitster@xxxxxxxxx> writes: > Glen Choo <chooglen@xxxxxxxxxx> 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.. Thanks. Also, I made a typo here, I meant to be more specific with regards to memset(), 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. _Do not use memset()._ Unless there really is a legitimate reason to use memset(&my_auto_var, 0 sizeof(my_autovar)) that I've missed? > 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. If I have time I'll send that proposal to CodingGuidelines, or someone else can send it (I don't mind either way).