Go version

go version go1.23.1 linux/amd64

Output of go env in your module/workspace:

GO111MODULE=''
GOARCH='amd64'
GOBIN=''
GOCACHE='/home/username/.cache/go-build'
GOENV='/home/username/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/home/username/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/home/username/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/usr/local/go'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/local/go/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.23.1'
GODEBUG=''
GOTELEMETRY='local'
GOTELEMETRYDIR='/home/username/.config/go/telemetry'
GCCGO='gccgo'
GOAMD64='v1'
AR='ar'
CC='gcc'
CXX='g++'
CGO_ENABLED='1'
GOMOD='/dev/null'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build3506538111=/tmp/go-build -gno-record-gcc-switches'

What did you do?

I want to write a function that converts C.char from Package A to C.char from Package B I wrote function like that

func ConvPointer[RESULT, SOURCE *any](ptr SOURCE) RESULT {
        return (RESULT)(unsafe.Pointer(ptr))
}

What did you see happen?

when calling this function I get:

../../typewrapper/type_wrapper.go:66:37: *_Ctype_char does not satisfy *any (*_Ctype_char missing in *any)

What did you expect to see?

any as the name suggests means anything, so why C.char is not anything? Is there a reason for that?

Comment From: gabyhelp

Related Issues and Documentation

(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)

Comment From: ianlancetaylor

That is how the language works. The type any is a name for the empty interface type interface{}. A value of type *C.char is a pointer to a C.char. A value of type *any is a pointer to a interface{}. The two are not compatible. See https://go.dev/doc/faq#convert_slice_of_interface, which is written in terms of []any but applies equally well to *any.

You can write your function as

func ConvPointer[ER, ES any, RESULT *ER, SOURCE *ES](ptr SOURCE) RESULT {
        return (RESULT)(unsafe.Pointer(ptr))
}

Closing because this is not a bug.

Comment From: gucio321

oh ok, I missed that, thank you!!