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

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -