go - Is there a builtin func named "int32"? -
go - Is there a builtin func named "int32"? -
the below snippet works fine. in case, "int32" is? func? know there type named "int32" stupid question. i've finished a tour of go not find answer.(it's possible i'm missing something.)
package main import "fmt" func main() { var number = int32(5) fmt.println(number) //5 }
it type conversion, required numeric types.
conversions required when different numeric types mixed in look or assignment. instance, int32 , int not same type though may have same size on particular architecture.
since variable declaration, need specify type of '5
'. option, mentioned rightfold in the comments is: var number int32 = 5
(as opposed short variable declaration number := 5
)
see go faq:
the convenience of automatic conversion between numeric types in c outweighed confusion causes. when look unsigned? how big value? overflow? result portable, independent of machine on executes?
it complicates compiler; “the usual arithmetic conversions” not easy implement , inconsistent across architectures.
for reasons of portability, decided create things clear , straightforward @ cost of explicit conversions in code. definition of constants in go—arbitrary precision values free of signedness , size annotations—ameliorates matters considerably, though.
a related detail that, unlike in c, int
, int64
distinct types if int
64-bit type. the int
type generic; if care how many bits integer holds, go encourages explicit.
go
Comments
Post a Comment