Re: [PATCH 5/5] cbtree.h: define cb_init() in terms of CBTREE_INIT
- From
Ævar Arnfjörð Bjarmason <avarab@gmail.com>
- Date
- Sep 27, 2021, 11:02 UTC
- Message-ID
- <87czou1dmp.fsf@evledraar.gmail.com>
- In-Reply-To
- <694f477d-b387-c8ea-4138-0e9334540c69@kdbg.org>
On Mon, Sep 27 2021, Johannes Sixt wrote:
Show 18 quoted lines
> Am 27.09.21 um 02:39 schrieb Ævar Arnfjörð Bjarmason:
>> --- a/cbtree.h
>> +++ b/cbtree.h
>> @@ -37,11 +37,12 @@ enum cb_next {
>> CB_BREAK = 1
>> };
>>
>> -#define CBTREE_INIT { .root = NULL }
>> +#define CBTREE_INIT { 0 }
>>
>> static inline void cb_init(struct cb_tree *t)
>> {
>> - t->root = NULL;
>> + struct cb_tree blank = CBTREE_INIT;
>
> This could be
>
> static const struct cb_tree blank = CBTREE_INIT;*nod*...
Show 8 quoted lines
>> + memcpy(t, &blank, sizeof(*t)); > > Is > *t = blank; > > not a thing in C? > > -- Hannes
...but to both this & the above my reply in the side-thread at https://lore.kernel.org/git/87h7e61duk.fsf@evledraar.gmail.com/ applies. I.e. this is just following a pattern I got from Jeff King & used in bd4232fac33 (Merge branch 'ab/struct-init', 2021-07-16).
FWIW with "const" in general I don't use it as much as I'd personally prefer, see e.g. [1] for one recent discussion, but maybe there wouldn't be any push-back in this case...
1. https://lore.kernel.org/git/patch-1.1-c317e6e125e-20210921T124416Z-avarab@gmail.com/