Thread (27 messages) 27 messages, 7 authors, 2021-09-30

Re: [PATCH 5/5] cbtree.h: define cb_init() in terms of CBTREE_INIT

flat view

From: Johannes Sixt <hidden>
Date: 2021-09-28 06:15:21

Am 28.09.21 um 01:54 schrieb Jeff King:
On Mon, Sep 27, 2021 at 01:02:35PM +0200, Ævar Arnfjörð Bjarmason wrote:
quoted
quoted
quoted
 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*...
[...]
...but to both this & the above my reply in the side-thread at
https://lore.kernel.org/git/87h7e61duk.fsf@evledraar.gmail.com/ (local)
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).
I'm not sure how a compiler would react to the "static const" thing. I
tested the compiler output for the "auto" struct case you've written
here, and at least gcc and clang are smart enough to just initialize the
pointed-to struct directly, with no extra copy.
Good! Then a deviation from established patterns is not warranted.

-- Hannes
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help