Unfortunately C varargs and Nim varargs are quite different from each other. C 
varargs are basically just a pointer to somewhere in memory and it's up to the 
callee to handle this collection of arbitrary data (typically done by C macros 
which will advance the pointer depending on the type you "took out" of the 
collection). Nim varargs can really only have one type and (I believe) is 
passed along as something more sequence like.

As another gotcha the `varargs` pragma [take a variable number of parameters 
after the last specified 
parameter.](https://nim-lang.org/docs/manual.html#foreign-function-interface-varargs-pragma),
 so your two definitions does not mean the same thing. In order to create a 
runtime dynamic list compatible with va_list (the type used by C varargs) you 
have to pack the arguments into one contiguous region of memory (with the 
correct padding) and pass a pointer of that to the function. Of course if 
you're only looking for a one-of or to generate this call with a macro then 
simply defining an object with all your data in order should suffice.

Reply via email to