Skip to content

Instantly share code, notes, and snippets.

@maxsei
Created September 26, 2022 19:54
Show Gist options
  • Select an option

  • Save maxsei/3217e4354d40964845cef09daf3f1fee to your computer and use it in GitHub Desktop.

Select an option

Save maxsei/3217e4354d40964845cef09daf3f1fee to your computer and use it in GitHub Desktop.
weird thing that happens when you try to create immutable arg function
package main
import (
"os"
"fmt"
)
func Args() []string{
args := make([]string, len(os.Args), 100)
fmt.Printf("os.Args: %v\n", os.Args)
fmt.Printf("args: %v\n", args)
fmt.Printf("copy: %v\n", copy(args, os.Args))
fmt.Printf("os.Args: %v\n", os.Args)
fmt.Printf("args: %v\n", args)
os.Args = nil
return args
}
func init() {
_ = Args()
}
func main() {
fmt.Printf("os.Args: %v\n", os.Args)
fmt.Printf("Args(): %v\n", Args())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment