Re: [PATCH v2 1/3] merge-base, xdiff: zero out xpparam_t structures
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Oct 12, 2020, 17:09 UTC
- Message-ID
- <xmqq1ri3qsll.fsf@gitster.c.googlers.com>
- In-Reply-To
- <nycvar.QRO.7.76.6.2010121313020.50@tvgsbejvaqbjf.bet>
Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:
Show 17 quoted lines
>> xpparam_t xpparam;
>> +
>> + memset(&xpparam, 0, sizeof(xpparam));
>
> A slightly more elegant way to do this would be
>
> xpparam_t xpparam = { 0l };
>
> Or even
>
> xpparam_t xpparam = XPPARAM_T_INIT;
>
> with
>
> #define XPPARAM_T_INIT { 0l, NULL, 0 }
>
> in `xdiff/xdiff.h`.Let's not suggest any of the above.
I think we had a recent thread [*1*] on which we agreed that "{ 0 }" is the way to spell "a naturally zero" initialization like this one, if we were to spell it out.
TBH, I'd say that memset() is also OK as-is in this codebase as an established way (git grep 'memset([^,]*, 0, sizeof' gives too many hits).
Thanks.
[Reference]
*1* https://lore.kernel.org/git/xmqq4knca7c6.fsf@gitster.c.googlers.com/