Why unused global variable allowed in Go?

package main

import (
	"fmt"
)

var x int

func main() {

	var z int
}

Why x is valid and z is not valid ? isn’t it another code pollution which is strictly prohibitated in Go?

1 Like

The compiler can determine that the local private variable z is unused. The compiler can’t determine that the global private variable x is unused, only the linker can do that.

2 Likes

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.