Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid behaviour with pointers #921

Open
zapateo opened this issue Nov 16, 2021 · 2 comments
Open

Invalid behaviour with pointers #921

zapateo opened this issue Nov 16, 2021 · 2 comments
Labels
InvalidBehavior A valid or not valid code has an invalid behavior at runtime needsInvestigation Need to investigate

Comments

@zapateo
Copy link
Member

zapateo commented Nov 16, 2021

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 #916.

@zapateo zapateo added needsInvestigation Need to investigate InvalidBehavior A valid or not valid code has an invalid behavior at runtime labels Nov 16, 2021
@zapateo
Copy link
Member Author

zapateo commented Nov 18, 2021

A simpler version of this issue:

package main

func main() {
	p := new(int)
	*p = 1
	*p += 5
	println(*p)
}

@zapateo
Copy link
Member Author

zapateo commented Nov 19, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
InvalidBehavior A valid or not valid code has an invalid behavior at runtime needsInvestigation Need to investigate
Projects
None yet
Development

No branches or pull requests

1 participant