btree.c
btree.c copied to clipboard
Q: what is the purpose of casting `mid` to `short` when adding to `nitems` which is `int`?
Hi, I’m trying to understand the types used in btree.c
and do not see what the purpose of this cast is, in line 498:
https://github.com/tidwall/btree.c/blob/9dbe6334730da5621d6bf17e4a34708bab16ffe3/btree.c#L498
It appears again at the end of that functon, again when assigning to node->nitems
.
Could you tell me what the idea is?
I think the casting between short
<-> int
<-> size_t
is no longer needed and can probably be safely removed.
It was left in there from an older commit where the nitems
field was a short, and the cast was needed to quiet warnings by the compiler.
But now the field is explicitly declared as a 16-bit size_t size_t:16
.
I just removed the cast with no noticeable issues.
I see, thanks for taking the time. I’ve incorporated that change in my fork.