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

c++ - Function signature as a function template parameter -

algorithm - What are some ways to combine a number of (potentially incompatible) sorted sub-sets of a total set into a (partial) ordering of the total set? -

How to call a javascript function after the page loads with a chrome extension? -