Created
September 26, 2022 19:54
-
-
Save maxsei/3217e4354d40964845cef09daf3f1fee to your computer and use it in GitHub Desktop.
weird thing that happens when you try to create immutable arg function
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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