How to use core.vararg to print D variadic arguments and their types without using ! (template instantiation)?

Steven Schveighoffer schveiguy at gmail.com
Sat Sep 16 16:55:15 UTC 2023


On 9/15/23 4:14 PM, Basile B. wrote:
> On Thursday, 14 September 2023 at 15:19:29 UTC, BoQsc wrote:
>> https://dlang.org/phobos/core_vararg.html
>>
>> The common way to use **va_arg** is `va_arg!(int)(_argptr);`
>> What would be the alternative way or syntax that behave exactly the 
>> same way, even if more verbose?
>>
>>
>>
>> ____
>> `va_arg!(int)(_argptr);` is taken from an example in:
>> https://dlang.org/spec/function.html#d_style_variadic_functions
> 
> here's how
> 
> ```d
> import core.vararg;
> 
> void main()
> {
>      foo(.5, 5);
> }
> 
> void foo(...)
> {
>      int i = void;
>      va_arg(_argptr, typeid(i), &i);
>      assert(i == 5);
>      double d = void;
>      va_arg(_argptr, typeid(d), &d);
>      assert(d == .5);
> }
> ```

Note that this doesn't work in gdc.

The templated version is actually more akin to what C does.

-Steve


More information about the Digitalmars-d-learn mailing list