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

2 messages, 2 authors, 2021-09-28 · open the first message on its own page

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

From: Junio C Hamano <hidden>
Date: 2021-09-28 18:33:07

Jeff King [off-list ref] writes:
quoted
quoted
quoted
+	memcpy(t, &blank, sizeof(*t));
Is
	*t = blank;

not a thing in C?
It would be fine to use struct assignment here, and should be equivalent
in most compilers. They know about memcpy() and will inline it as
appropriate.
FWIW, I'd be fine with structure assignment, but we already have too
many such memcpy(<ptr>, &<struct>, sizeof(struct)), adding one more
is not giving us too much incremental burden for later clean-up.
I think some C programmers tend to prefer memcpy() just because that's
how they think. It also wasn't legal in old K&R compilers, but as far as
I know was in C89.
I think so, too.

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

From: Ævar Arnfjörð Bjarmason <hidden>
Date: 2021-09-28 19:43:43

On Tue, Sep 28 2021, Junio C Hamano wrote:
Jeff King [off-list ref] writes:
quoted
quoted
quoted
quoted
+	memcpy(t, &blank, sizeof(*t));
Is
	*t = blank;

not a thing in C?
It would be fine to use struct assignment here, and should be equivalent
in most compilers. They know about memcpy() and will inline it as
appropriate.
FWIW, I'd be fine with structure assignment, but we already have too
many such memcpy(<ptr>, &<struct>, sizeof(struct)), adding one more
is not giving us too much incremental burden for later clean-up.
quoted
I think some C programmers tend to prefer memcpy() just because that's
how they think. It also wasn't legal in old K&R compilers, but as far as
I know was in C89.
I think so, too.
Getting back to the topic of this v2 in general, my reading of the
discussion since then is that nothing in it necessitated a v3 re-roll to
address outstanding issues. If I've got that wrong please shout...
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help