btree.c icon indicating copy to clipboard operation
btree.c copied to clipboard

Q: what is the purpose of casting `mid` to `short` when adding to `nitems` which is `int`?

Open AlbertoGP opened this issue 11 months ago • 3 comments

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?

AlbertoGP avatar Mar 11 '24 10:03 AlbertoGP

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.

tidwall avatar Apr 14 '24 13:04 tidwall

I just removed the cast with no noticeable issues.

tidwall avatar Apr 14 '24 14:04 tidwall

I see, thanks for taking the time. I’ve incorporated that change in my fork.

AlbertoGP avatar Apr 14 '24 15:04 AlbertoGP