3 ms·
> They are confusing (as in, the answer to question: how many bits are there in your int, long, short depends on both arch and compiler) and since 70s we discov
by int_19h 8y ago
> They are confusing (as in, the answer to question: how many bits are there in your int, long, short depends on both arch and compiler) and since 70s we discovered it the hard way that they're non-extensible (multiple times, actually!).
Did we though? The original design, as it was in ALGOL 68, was very much extensible - it specifically said that SHORT and LONG are 1) prefixes, not types, and 2) any amount of them is valid, but the implementation only has to provide SHORT INT, INT and LONG INT, and then the rest are there for shorter and longer implementation-defined types.
What broke it in C mainly that instead of the obvious sequence of short-int-long being 16/32/64 from the get go, they have reused int to mean "most common type". So the original 16-bit architectures had short and int being basically the same, making short redundant. Then on 32-bit, int was changed, but again in a broken way where it was now mapped to long, making that redundant (but still heavily used!). Which set up the 64-bit disaster, where Windows wouldn't make long 64-bit because too much code was out there assuming that it was 32-bit.
If we kept short/int/long separate all along, and didn't try to redefine them afterwards, we wouldn't even need long long today.
- tagrun 8y agoI'd rather say having such ambiguous adjectives for types was a bad idea to begin with. And it falls apart when something longer than the original long comes out. I'm not blaming them for not being explicit about the # of bits back then, though, because back then memory addressing unit (byte) wasn't universally 8-bits and word size wasn't a multiple of 8 either (and some archs weren't even binary): https://en.wikipedia.org/wiki/Word_(computer_architecture)#Table_of_word_sizes https://en.wikipedia.org/wiki/Word_(computer_architecture)#T... It seems a naming convention in units of bytes could've been possible though (with the exception of a few archs).
- int_19h 8y agoThe original design doesn't fall apart, because it allowed multiple prefixes - LONG INT, LONG LONG INT etc - from the get go, specifically so that the list of types could be extended arbitrarily. It's not the most concise or descriptive way to name them, but that's an issue distinct from extensibility. Personally, I think that rather than focusing on number of bits for numeric types, type systems should focus on the valid range of values, more along the lines of Pascal and Ada.
- tagrun 8y ago"long long" is proof that it falls apart. Short/long were descriptive, meaningful adjectives, and in the context of 3 integers of different sizes, it made sense. "long long" isn't a descriptive or meaningful adjective. It's not even a real word. Luckily, there are signs that this will stop. Non-standard 128-bit integers are called __int128_t rather than "long long long".