3 ms·
Now do a closed range in type uint8_t representing [0x00, 0xff] Or how about a closed range in uint64_t that ends at 0xffffffffffffffff Or a range from roughl
by stabbles 6y ago
Now do a closed range in type uint8_t representing [0x00, 0xff]
Or how about a closed range in uint64_t that ends at 0xffffffffffffffff
Or a range from roughly a = -9223372036854775808 to b = 9223372036854775807 in int64_t. b - a will overflow.
- user-the-name 6y agoHow about an empty range in type uint8_t? The fact of the matter is, for a type that can hold N distinct values, there are N + 1 different possible interval lengths. You can not represent intervals over a fixed-width type in that same type.
- stabbles 6y agoExactly, there's no silver bullet for ranges
- samatman 6y agoDid you mean open range? I've never encountered a circumstance where closed ranges are useful, though I presume they exist. And yes, I think any typed language with a less expressive range syntax than Ada has some work to do. That still leaves open the question of the default, and I maintain that 0 <= .. < n is the correct one.