I am some ‘memory allocator’ type code, by using an array and indexes rather than pointers. I’m hoping that the size of the index of the array is smaller than a pointer. I care because I am storing ‘pointers’ as integer indexes in an array rather than 64-bit pointers.
I can’t see anything in the Go spec that says what an array is indexed by. Obviously it’s some kind of integer. Passing very large values makes the runtime complain that I can’t pass negative numbers, so I’m guessing that it’s somehow cast to a signed integer. So is it an int32? I’m guessing it’s not an int64 because I didn’t touch the top bit (which would have been 2’s compliment for a negative number).
Arrays may be indexed by any integer type.
The Array types section of the Go Programming Language Specification says that in an array type definition,
In an index expression such as
a[x]:But there is a limitation on the magnitude of an index; the description of Length and capacity says:
So the declared size of an array, or the index in an index expression, can be of any integer type (
int,uint,uintptr,int8,int16,int32,int64,uint8,uint16,uint32,uint64), but it must be non-negative and within the range of typeint(which is the same size as eitherint32orint64— though it’s a distinct type from either).