Re: [PATCH] git-compat-util.h: introduce CALLOC(x)
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Dec 6, 2022, 01:35 UTC
- Message-ID
- <xmqqv8mpnwjp.fsf@gitster.g>
- In-Reply-To
- <Y46ZJUsyp8UW5rFW@coredump.intra.peff.net>
Jeff King <peff@peff.net> writes:
Show 8 quoted lines
> So you can think of "allocate this one element and zero it" as "calloc, > but don't multiply" or as "malloc, but zero". Naming it CALLOC() is > thinking of it as the former. If we think of it as the latter it could > perhaps be MALLOCZ() or something. I don't know if that name is too > subtle or not. We have xmemdupz(), which is basically the same thing; > it's only a zero-terminator, but that is because we are writing non-zero > bytes in the rest of it. Mostly I'd worry that it is easy to glance past > the "Z".
I think the name for the former would be CALLOC_ONE(), as I would rephrase it as "calloc, but just one element". I agree MALLOCZ() would be fine for the other interpretation, and I do not have much problem as much problem with the name as calling it CALLOC().
Thanks.