How to convert C unsigned char * to golang string

803 views
Skip to first unread message

tyeen...@gmail.com

unread,
Dec 16, 2019, 11:51:33 PM12/16/19
to golang-nuts
I am using CGO to call a .so library written by C, and it has a param 
unsigned char *result_buffer

I use a C.uchar to receive its result, but how to convert it a Go string?


Ian Lance Taylor

unread,
Dec 16, 2019, 11:56:25 PM12/16/19
to tyeen...@gmail.com, golang-nuts
You should receive the result in a *C.uchar. You can get a Go string
by calling something like C.GoString((*C.char)(unsafe.Pointer(p))).
See https://golang.org/cmd/cgo.

Ian
Reply all
Reply to author
Forward
0 new messages