tbh, this raises confusing if you were programming in java or cpp
评论:
iroflmaowtf:
:https://golang.org/pkg/builtin/#int
int is a signed integer type that is at least 32 bits in size. It is a distinct type, however, and not an alias for, say, int32.
TheMerovius:[deleted]
nsd433:int is 64 bits on 64-bit platforms, and 32 bits on 32-bit platforms.
nit: int is either int32 or int64; an implementation can choose whatever it wants, no matter what platform it runs on (for example, GopherJS on my laptop runs on a 64 bit platform, but uses int32 for ints, as they have to fit in a float64).
faiface:As others have said, int and int32 are not the same, and that's why you have both. Most of the time you want a reasonable int. Other times you want an int which truncates at 32 bits.
You mention C++. C and C++ have the same destinction. In C/C++ 'int' is a reasonable integer size on the target CPU, and int32_t is a signed integer with exactly 32 bits.
irene634:Surprised no one mentioned that int usually has 64 bits on 64-bit systems and 32 bits on 32-bit systems. The distinction from both int32 and int64 is clear.
faiface:If that is correct, it is the same to use int and int64 on 64-bit systems?
No. On 64-bit systems, both types allow same sets of values, but are different in the Go type system and values of one need to be explicitly converted to the other.
