How one would increment cRetValue pointer in go code to access the 
successive bytes ?

*cRetValue gives me the zeroth byte only. How to get the 2nd, 3rd byte? The 
case I have has a pointer to array of structs in C land and I want to 
iterate over them in Go.

Thanks!!


On Sunday, April 17, 2016 at 9:54:58 PM UTC-7, Ian Lance Taylor wrote:
>
> On Sun, Apr 17, 2016 at 8:51 PM, Ray Yang <rayya...@gmail.com 
> <javascript:>> wrote: 
> > 
> > Now after some experiment, I have the following solution to have 
> returnValue 
> > passed back from the C callee. However, as it's said that C.GoString 
> > allocates some memory, I have to free it in the C function before set it 
> to 
> > a new value. 
> > 
> > Is there a better way to avoid such extra memory freeing? I try to use 
> > "c_retValue := C.CString(nil)" but "go build" complains "cannot use nil 
> as 
> > type string in argument to _Cfunc_CString" 
>
> Don't pass C.CString(nil).  Write something like 
>     var cRetValue *C.char 
>     ret := bool(C.func(&cRetValue)) 
>
> (And, for style reasons, don't write `if ret == true`, just write `if 
> ret`.) 
>
> Ian 
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to