scriggo
scriggo copied to clipboard
Invalid behaviour with pointers
Source code
package main
import "fmt"
var P = new(int)
func main() {
fmt.Println(*P)
*P = 32
fmt.Println(*P)
*P++
fmt.Println(*P)
}
Scriggo output
0
32
4
gc output
0
32
33
Details
Note that this issue has been opened after closing https://github.com/open2b/scriggo/issues/916.
A simpler version of this issue:
package main
func main() {
p := new(int)
*p = 1
*p += 5
println(*p)
}
Note that this code:
package main
func main() {
p := new(int)
*p = 1
_ = *p
*p += 5
println(*p)
}
works as expected. The only difference with the previous one is the addition of _ = *p
.