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

copy/pass by value versus this library #47

Open
ORESoftware opened this issue Feb 15, 2020 · 1 comment
Open

copy/pass by value versus this library #47

ORESoftware opened this issue Feb 15, 2020 · 1 comment

Comments

@ORESoftware
Copy link

ORESoftware commented Feb 15, 2020

so if I have a struct:

package main

import "log"

var s = struct{Foo string}{"foo"}

func acceptStruct(a interface{}, b interface{}) bool {
	return a == b
}

func main() {
	log.Println(acceptStruct(s, &s))
}

will the first argument be copied - and how is the copy different than the deep copy that this library uses?

@RayfenWindspear
Copy link

RayfenWindspear commented Mar 18, 2020

For starters, your acceptStruct function isn't making the comparison you think it is, a struct pointer will never be equal to a struct value. Second, yes you can do a shallow copy with a function, or just dereferencing a pointer, but it's only shallow.

See example: https://play.golang.org/p/eaFXASIXV7A

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants