Hacker News new | ask | show | jobs
by iand 4594 days ago
Note that this is from 2009. Although the main details have not changed, the int type is more commonly 64 bits now (since 64 bit architectures are much more common)
1 comments

Do you know what version that happens in? I tested on my 32 and 64 bit platforms with golang 1.1 and a static definition of an integer results in type int (which is explicitly 32 bit)

  package main
  import "fmt"
  import "reflect"
  func main() {
      i := 3
      z := reflect.ValueOf(i)
      fmt.Printf("%s\n", z.Kind()) 
  }
  // $./test
  // int
  // $
It's my understanding that this intentional and won't change, only explicit declarations of int64 are 64-bit.
It is implementation-specific (from the spec:)

There is also a set of predeclared numeric types with implementation-specific sizes:

uint either 32 or 64 bits

int same size as uint

uintptr an unsigned integer large enough to store the uninterpreted bits of a pointer value

The size of int on 64-bit systems was increased to 64 bits as of Go 1.1: http://golang.org/doc/go1.1#int
Cool, thanks for the clarification, this makes sense!
i := 3 means declare i to be an "int", which is the default numeric type. The size of that int will vary from platform to platform. See http://golang.org/ref/spec#Numeric_types
Awesome, thanks!