vfprintf equivalent in D
Jonathan M Davis
jmdavisProg at gmx.com
Thu Feb 23 21:41:12 PST 2012
On Thursday, February 23, 2012 21:38:27 Jonathan M Davis wrote:
> On Friday, February 24, 2012 05:22:58 Sarath Kumar wrote:
> > Hi,
> >
> > Is there an equivalent to vfprintf(const char *fmt, , va_list ap) in D?
>
> If you're dealing with C variadics, then your going to need to use C
> functions. D doesn't just recreate C functions (at least, the standard
> library doesn't). C functions get wrapped when doing so adds some benefit,
> but with something like this, there's no reason to.
>
>
> If you're using typesafe variadics
>
> void func(int[] arr...)
>
> then you can just pass the array to the next function.
>
>
> If you're using D-style variadics (which are similar to C variadics but
> include type information), maybe there is, I don't know. Probably. I never
> use them.
>
>
> However, the typical thing to do in D is to use variadic templates. That's
> what writefln does.
>
> void func(Args...)(Args args)
>
> And with that, you can just pass the arguments on to another function.
>
>
> http://dlang.org/function.html
> http://dlang.org/template.html
And if your intention was to specifically pass on arguments to writefln, then
you can just do it, since it's a variadic template.
void myWritefln(Args...)(Args args)
{
writefln(args);
}
But if you're looking to specifically pass on a C variadic, then use C's
vfprintf.
- Jonathan M Davis
More information about the Digitalmars-d-learn
mailing list