DEV Community

Discussion on: Should a modern programming language assume a byte is 8-bits in size?

Collapse
 
nestedsoftware profile image
Nested Software • Edited

Hmm. Since C defines the result of sizeof as a number of 'bytes' (but not necessarily octets, as you pointed out), I guess it makes sense to do the same for code who's job is to help interface with C code. You could try to call it something else, but I'm finding it hard to think of something better. 'sizeof_type'?

Thread Thread
 
mortoray profile image
edA‑qa mort‑ora‑y

byte is the term that means this in C/C++, and historically is the correct term as well. It's only recently that it's become an alias for 8-bits. I don't think I'd like to introduce a new term.

Leaf will also have to have a sizeof that returns number of bits. I guess it won't be so unnatural to have mismatched values though, since you can use arbitrary bit sizes anyway:

  • sizeof(integer 7bit) = 1
  • sizeof(integer 8bit) = 1
  • sizeof(integer 9bit) = 2