Original post

If I compile the code below:

package main

import (
        "fmt"
        "math"
)

func main() {
        b := uint32(-1)
        fmt.Printf("%d, %v, %bn", b, b == math.MaxUint32, math.MaxUint32)
}

I got an error:

constant -1 overflows uint32

But if I change the code:

package main

import (
        "fmt"
        "math"
)

func main() {
        a := -1
        b := uint32(a)
        fmt.Printf("%d, %v, %bn", b, b == math.MaxUint32, math.MaxUint32)
}

It works. I’m wondering the reason, can somebody explain? thx :slight_smile: