3 ms·
People have traditionally wanted to use the maximum sized type that can fit in a register.
by drb91 8y ago
People have traditionally wanted to use the maximum sized type that can fit in a register.
- user5994461 8y agoTraditionally the register size was too small, it's very common to have numbers above 256 or 65536. It's not true anymore with 32 bits numbers and a limit of 2 billion.
- Someone 8y agoMore precisely: they wanted the integer type that was large enough and ran their code fastest. On CPUs with 64-bit and 32-bit registers, that typically is the register-sized integer type. Machines with 16-bit registers are a bit of an edge case, as 16-bit integers may both be a lot faster on them then 32-bit integers and, in many cases, too small) If go chose to use 32-bit integers as default, some users on 64-bit systems would complain that they couldn’t create, say, an array of 6 billion ints. If they chose 64-bit, some users on 32-bit systems would complain their loops were needlessly slow, and code bloated (why waste 4 bytes of almost every integer in a program?) Not having generics makes this more of a problem. If go had generics, switching between integer sizes could be a matter of recompilation using a different compiler flag) A sufficiently advanced compiler would help here, but go doesn’t have one (not exceptional), and doesn’t even aim to have one (compilation speed seems more of a goal than run-time speed)
- TheDong 8y ago> Not having generics makes this more of a problem. If go had generics, switching between integer sizes could be a matter of recompilation using a different compiler flag) Isn't it already the case that you can switch between int sizes with compiler flags? var i int That will be 32 bits if I compile it with GOOS=linux GOARCH=386 and will be 32 bits if I swap in amd64 instead of 386 there. Is there any language where generics are useful for switching between int sizes? None come to mind offhand, so I don't quite understand what you mean.