db_tutorial icon indicating copy to clipboard operation
db_tutorial copied to clipboard

Regarding uint8_t in node header definition

Open Ahacad opened this issue 4 years ago • 1 comments

Hello, I'm still a learner of the c programming language and database. The below line has uint8_t but the definitions above it are all uint32_t, I think they should use the same def, all uint8_t or all uint32_t, is there any detail here I didn't notice?

https://github.com/cstack/db_tutorial/blob/051b5c0b142650d357e89757318f88051e3d41b0/db.c#L96

Ahacad avatar May 07 '21 12:05 Ahacad

It's a matter of opinion in code and some people want to use the smallest datatype necessary. Possibly because it conveys some information to the reader that a header size won't be more than 255, whatever the number is.

This is more common in larger data structures. Say you have an absolute binary offset: you'll probably store it as a uint_64 to be safe (able to store offsets into several GBs) - meanwhile a magic header (like PNG) will be uint_8 since it's only a few bytes.

tsugabloom avatar May 08 '21 06:05 tsugabloom