Re:Go 2, here we come
by Sharlin on Thursday November 29, 2018 @02:57PM
(#18563382)
It may be crazy but it's not exactly without precedent. Neither C nor C++ fix the sizes of the fundamental integer types, although for backward-compatibility reasons popular 64-bit platforms still have 32-bit `int` and even `long`. But yeah, there's a reason eg. Rust has no `int` and friends but `i32` etc. instead.
[ Parent
| on HN ]
Rust has a `usize` which is 32 or 64 bits depending on the platform and also serves as the native index type for arrays and such.
Yeah, that makes sense because you need some type to span the address space and that depends on the size of the address space. That is what int is used for in go, though why they chose signed rather than unsigned is confusing. unsigned you would never have to do negative bounds checks and you can prove a lot of other useful things if you know your index is always positive.
I don't know how go does it, but in some languages negative indices count backwards from the rear end. E.G. myarr[-1] == myarr[myarr.length-1].
Re:Go 2, here we come
by lemoncucumber on Thursday November 29, 2018 @03:42PM
(#18563794)
Right, 64-bit Windows has 32-bit int and long and 64-bit long long (LLP64) while 64-bit unixes generally have 32-bit int and 64-bit long/long long (LP64).
Re:Go 2, here we come
by user5994461 on Thursday November 29, 2018 @03:13PM
(#18563513)
C only defines char, short, int has having a minimum size of 8, 16 and 32 bits.
Actually C defines the minimum size of "int" as 16 bits, because it defines the minimum range it should support as [-32768 .. 32767]
Nit: [-32767 .. 32767]
C permits ones' complement and sign-and-magnitude as well as two's complement.