by e63f67dd-065b · 4y ago · 0 comments
The idea to separate bit vectors from numbers is a good one though, it always seemed a little weird to me that we're passing around numeric types for FLAG_FOO & FLAG_BAR.
In low-level code, integer types are not numbers. They are fixed-length bit fields with a numerical interpretation. One thing I like in Rust over C/C++ is that it makes this clear. You always specify the size and signedness of the integer explicitly, and the standard library provides many useful operations beyond the operators.
Also "character strings" were a distinct type.
I also believe that these types must be clearly distinguished, even if conversion functions must be provided between them, and even if in certain contexts it may be convenient for the conversions to be implicit.
That’s because lots of hardware back then had support for bit addressing. The machine I love the best, the PDP-6/PDP-10 had addressable bytes of width ranging from 1-36 bits, which were extremely handy.
The few C compilers for those machines didn’t support them of course because the PDP-11s didn’t support them, but C on the PDP-10 was only used for porting stuff anyway.
Honestly I’m surprised they haven’t been revived. Packed bitfields are really handy and should be fast.
ARM has bit addressing with their bit-banding feature where individual bits are mapped onto byte addresses.
When you have a very large dataset tricks like this can significantly reduce RAM and especially cache pressure.