cgo: How to convert C's struct to go unsafe.Pointer

cgo: How to convert C's struct to go unsafe.Pointer

If an error is reported during go build:
cannot use _cgo5 (type _Ctype_struct__xx) as type unsafe.Pointer in argument.
for example, the function declaration in the C function is int SetUserData(void * userData), where userData is a struct.
This method can be used to convert the C struct to go unsafe.Pointer:

var a C.UserData
udata := unsafe.Pointer(&a)
C.SetUserData(udata)

Guess you like

Origin blog.csdn.net/huzhenwei/article/details/113048541