On Wed, Jan 24, 2018 at 3:00 PM, Christian LeMoussel <cnh...@gmail.com> wrote:
> Thank you Bryan for your advice. > In examples, I see how to pass the Go pointers directly. > > For example : > h := C.CString(name) > defer C.free(unsafe.Pointer(h)) > gerrno, err := C.getaddrinfo(h, nil, &hints, &res) > To > h := make([]byte, len(name)+1) > copy(h, name) > gerrno, err := C.getaddrinfo((*C.char)(unsafe.Pointer(&h[0])), nil, > &hints, &res) > > But I found nothing on how to append an extra 0 to the slice. > That's what the +1 in make([]byte, len(name)+1) does: it pads the buffer by an extra byte, which make will initialize to 0. -- 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.