5 ms·
I'm far more partial to the idea that NaN was a mistake than a desired feature. Including it then making operations that involve it UB is a road to hell and sad
by e63f67dd-065b 4y ago
I'm far more partial to the idea that NaN was a mistake than a desired feature. Including it then making operations that involve it UB is a road to hell and sadness, far worse than abs(INT_MIN).
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.
- codeflo 4y agoI mean, strongly typed flag values are a solved problem. It’s not rocket science, just bothersome to do in C++.
- adrian_b 4y agoAlready in 1964 the language PL/I (still named NPL in 1964) had "bit strings" as a distinct type from integer numbers. 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.
- gumby 4y ago> Already in 1964 the language PL/I (still named NPL in 1964) had "bit strings" as a distinct type from integer numbers. 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.
- kevin_thibedeau 4y ago> I’m surprised they haven’t been revived. ARM has bit addressing with their bit-banding feature where individual bits are mapped onto byte addresses.
- gumby 4y agoThat's handy, and I suppose much faster than mask & shift. But it's often handy to be able to stride through an array at, say, three bits at a time. When you have a very large dataset tricks like this can significantly reduce RAM and especially cache pressure.
- jltsiren 4y agoIf you are doing bit manipulation that's more complicated than vectors of boolean flags, you are likely going to use both bitwise and arithmetic operations on the same data. If you need separate types for those operations, you will need many explicit casts in your code. That is usually a sign that something is wrong. 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.