DEV Community

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

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

The immediate case I'm trying to solve is a C-union used in the SDL library. To solve it I'm going to create a byte-buffer large enough to hold all the types and allow casting it to the correct type.

Hopefully byte doesn't come up often in Leaf, only for integration and low-level work. There's no real cost associated with supporting it, other than having to explain that byte != octet. There's also no real way of enforcing this either, since on all current OS's they will be the same type. Making them strongly different types might be quite inconvenient, but it's something I'm considering.

That is, even if the same size, don't allow byte <-> octet conversions without explicit casting.

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