|
|
|
|
|
by chrisco255
501 days ago
|
|
> Huh? How do you think `const char s = "Hello"; const char t = &s[1];` works? So this is just an example of a pointer offset by 1 slot. It's not conceptually all that different to take sub-values of a slot. To work with values that consume fractions of a byte, such as a 3-bit integer, a pointer + a bit offset is used to grab that value (that complexity is abstracted by the compiler). My argument is the bit shift necessary to load the 3-bits you
need from the 8-bit slot is one of the cheapest operations a CPU can do. Meanwhile using 3-bits when all you need is 3-bits allows for things like arrays and packed structs to use much less memory than padding everything to 8 bits. And why shouldn't a language support that? |
|
If some pointers have a bit offset but others don't, OK, I guess, but I'd argue that at that point it'd be a cleaner design to just have a "pointer plus bit offset" be a separate type from "regular pointer". And that would get back to the problem that you would have a type that you couldn't take a "regular" pointer to.