Wrapping c variadic functions

James Miller james at aatch.net
Thu Feb 23 03:58:20 PST 2012


On 23 February 2012 23:35, simendsjo <simendsjo at gmail.com> wrote:
> Say i have a c function (didn't include first format argument for
> simplicity)
>
> void print(...);
> I wrap it up:
> extern(System) void print(...);
>
> And then I try to wrap it up in some safer D way:
> void print(Args...)(Args args)
> {
>    print(args); // only the first argument is printed
> }
>
> void print(...)
> {
>    print(_argptr); // no go either
> }
>
> How am I supposed to do this? http://dlang.org/function.html#variadic
> doesn't make my any smarter.

I'm pretty sure that std.c.stdarg is where you want to go,
unfortunately, due to the fact that C varargs is a bit of black magic,
you can only really wrap functions that provide v* versions. On top of
that, std.c.stdarg is just a wrapper for the C library of the same
name, so it doesn't provide a proper way to convert anything to a
va_list.

However, if you experiment with v* functions from C, then you might be
able to trick it...


More information about the Digitalmars-d-learn mailing list