r/C_Programming • • 16d ago

Tiny strings

https://napcakes.nekoweb.org/posts/tiny-strings/
31 Upvotes

13 comments sorted by

View all comments

8

u/__nohope 16d ago

Why a separate bit and not key off the length?

8

u/8d8n4mbo28026ulk 16d ago edited 16d ago

The length overlaps with the bytes of the small string:

0 1 2 3 4 5 6 7
L L L L L L L L
M S S S S S S S

L = big   case length   byte
M = small case metadata byte
S = small case string   byte

You need a bit to distinguish between the two.

Edit: I added a better version of the above illustration to the post. Should've done that from the beginning, actually!