Why does max int listing cause a compilation error in golang?

Here is the link to go playground

package main

import "fmt"
import "math"
func main() {
    fmt.Println("Hello, playground")
    fmt.Println(math.MaxUint32)
}

The above code calls

constant 4294967295 overflows int

does it fmt.Printlnautomatically convert each number to int?

+4
source share
1 answer

Go programming language specification

Constants

An untyped constant has a default type, which is the type with which the constant is implicitly converted in contexts where a typed value is required. By default, the type of the untyped constant is bool, rune, int, float64, complex128 or string, respectively, depending on whether it is a logical, runic, integer, floating-point, complex or string constant.

func Println(a ...interface{}) (n int, err error)

fmt.Println(math.MaxUint32)

math.MaxUint32 - , int , interface{}.

int - 32- 64- .

const (
    MaxInt32  = 1<<31 - 1
    MaxUint32 = 1<<32 - 1
)

MaxUint32 MaxInt32.

go env, , 32- , GOARCH="386".

32- int . . ,

fmt.Println(uint32(math.MaxUint32))
+6

All Articles