4 ms·
> I don't think I've ever been in a situation where I thought "I need this variable to have a type that's the 3rd smallest available, but I don't care how many
by ajross 3y ago
> I don't think I've ever been in a situation where I thought "I need this variable to have a type that's the 3rd smallest available, but I don't care how many bits it actually is. On some platforms, it will overflow at 32768, and on other platforms it will overflow at 2.1 billion, and I'm fine with either behavior."
No, but you've probably been in a situation where "I need this variable to fit in a register", no?
- chihuahua 3y agoOk, then it would make sense to have ONE datatype that fits a register. But it would make more sense that the other types (char, short, long) are a known and fixed size. Otherwise, what's the use case for short? "I need something that's smaller than a register, but I don't care what range it can store?"
- ajross 3y agoFWIW "short" has always been 16 bits. It was introduced with VAX Unix (and a few other 32 bit architectures) so that you could easily port code that assumed 16 bit arithmetic. The point isn't that, today, you'd choose to do what C did. But in 1977 there weren't a lot of other options. Early C did indeed have fixed, defined types. But moving to the VAX messed all that up. They had to choose to either add new types (and thus turn a bunch of code that would otherwise run fast on the VAX into weirdly-interpreted nonsense) or update the existing types so that idiomatic PDP-11 code still did what you expect most of the time. They chose the latter.