c - From []byte to char* -


i want wrap c function takes char* pointing (the first element of) non-empty buffer of bytes. i'm trying wrap in go function using cgo can pass []byte, don't know how conversion. simplified version of c function's signature is

void foo(char const *buf, size_t n); 

i tried passing pointer first byte in slice with

c.foo(&b[0], c.size_t(n)) 

that doesn't compile, though:

cannot use &b[0] (type *byte) type *_ctype_char in function argument 

so what's correct procedure here? go-wiki describes reverse situation.

ok, turned out easier thought:

(*c.char)(unsafe.pointer(&b[0])) 

does trick. (found @ golang-nuts.)


Comments

Popular posts from this blog

Winapi c++: DialogBox hangs when breaking a loop -

vb.net - Font adding using PDFsharp -

javascript - jQuery iScroll clickable list elements while retaining scroll? -