vsprintf or printf variable arguments

kink via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Aug 5 01:32:42 PDT 2016


On Thursday, 4 August 2016 at 21:03:52 UTC, Mark "J" Twain wrote:
> How can I construct a va_list for vsprintf when all I have is 
> the a list of pointers to the data, without their type info?
>
> A va_list seems to be a packed struct of values and/or pointers 
> to the data. While I could construct such a list, 
> theoretically, I don't always know when I should store an 
> element as a pointer or a value.
>
> e.g., ints, floats, and other value types seems to get stored 
> directly in the list, while strings and *other* stuff get 
> stored as pointers.
>
> I would be nice if a printf variant listed takes only a pointer 
> list to all the values, does anything like this exist?
>
> If not, is there any standardization of what is a value in the 
> list and what is a pointer so I can attempt to build the list 
> properly?

This has absolutely nothing to do with D as these are C 
functions, so you'd be better off asking this in another forum. 
Anyway, I have no idea why you'd want to construct the va_list 
manually. These vprintf() functions only exist so that other 
variadic functions can forward THEIR varargs - e.g.,

extern(C) void myOldschoolPrintf(in char* format, ...)
{
   doSomethingSpecial();
   va_list myVarargs = va_start(format);
   vprintf(format, myVarargs);
}

Note that va_list is highly platform-dependent, so filling the 
struct manually is a very bad idea.


More information about the Digitalmars-d-learn mailing list