3 ms·
This was common in Wirth languages eg Pascal, where they are called “sub-range types” https://wiki.lazarus.freepascal.org/subrange_types https://wiki.lazarus.fr
by willvarfar 5y ago
This was common in Wirth languages eg Pascal, where they are called “sub-range types” https://wiki.lazarus.freepascal.org/subrange_types https://wiki.lazarus.freepascal.org/subrange_types
It’s something I actually miss in modern mainstream languages. But as it’s something few copied and few lament, we can extrapolate that I’m a minority :)
C99 has something similar but different in that integer fields in a struct can have a bit width specifier. This is is primarily used for bit fields in protocol frames and things, and conventional wisdom is that compilers generate poor code for them even today, and doing your own bit masks instead is still popular.
- auxym 5y agoNim's type system was inspired by Wirthian languagrs and it does have subranges.
- Animats 5y agoI wanted that in Ada, which has subranges. I wanted "ranges" instead - no mention of the underlying hardware at all. Intermediate values would be sized based on the rule that you can't overflow an intermediate value unless it would lead to overflow of the final sized value. Sometimes this requires longer intermediate values. What happened instead was standardized hardware. The 60 bit CPUs, the 48 bit CPUs, the 36 bit CPUs, the 24 bit CPUs, the 18 bit CPUs, and the 12 bit CPUs all died off. With everybody using powers of 2 of bytes, range calculation became less important for portability.