On Thu, Jun 4, 2015 at 1:47 PM, Jsor <
jrago...@gmail.com> wrote:
>
> I know that cgo doesn't do varargs, but I came across a stack overflow
> question suggesting to wrap it, however, as far as I can tell, there's no
> way to pass an array as varargs either. Does anyone know a workaround?
cgo works by generating C code to call the C function. The nature of
C varargs is that the arguments must actually be written out in the
calling C code. C has no equivalent to Go's F(args...). So this is
insoluble in principle. There is no way to generate C code to call a
C function with an unknown number of arguments.
That said, if there is some reasonable limit on the number of
arguments, you can force the Go side to extra unused arguments to each
call. That is basically what the syscall package does, with Syscall3,
Syscall6, and Syscall9.
Ian