You need to read https://golang.org/pkg/unsafe/#Pointer *very, very, very* carefully before using unsafe.Pointer in any way. It spells out 6 conversions that are considered "valid". It says: "Code not using these patterns is likely to be invalid today or to become invalid in the future." AFAICT, your code does not fit any of those 6 allowable patterns.
Go is simple and easy, CGO is tricky, difficult and full of dragons. On Thursday, February 13, 2020 at 11:42:30 AM UTC-5, Alex wrote: > > I have to pass C pointers between packages so I used uintptr like how > syscall does things. > However go vet gives the message "possible misuse of unsafe.Pointer". > > Is there something I could do to avoid vet complaining? > > Package A: > type Foo struct { > procAddr uintptr > } > > func (f Foo) ProcAddr() uintptr { > return f.procAddr > } > > func Bar() Foo { > return Foo{C.SomeFunc()} > } > > Package B: > p := C.ASDF(unsafe.Pointer(A.Bar().ProcAddr())) // possible misuse of > unsafe.Pointer > > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/a726d6d5-5908-4f08-a5d6-1a6b50d89bf2%40googlegroups.com.