vfprintf equivalent in D

Jonathan M Davis jmdavisProg at gmx.com
Thu Feb 23 21:38:27 PST 2012


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

- Jonathan M Davis


More information about the Digitalmars-d-learn mailing list