variadic args

JohnC johnch_atms at hotmail.com
Thu Dec 7 07:45:08 PST 2006


"novice2" <sorry at nom.ail> wrote in message 
news:el9brb$lug$1 at digitaldaemon.com...
> can i pass variadig arguments from one function to other?
> siomething like:
>
> void func1(...)
> {
>  func2(...);
> }
>
> is it still not possible?
>
> (sorry, i was asked this some time ago. but now i see array
> literals are mnaked and other good changes - may be this question
> changed too.)

This is what I do:

import std.stdarg;

void resolveArgs(inout TypeInfo[] arguments, inout void* argptr) {
  if (arguments.length == 2 && arguments[0] is typeid(TypeInfo[]) && 
arguments[1] is typeid(void*)) {
    arguments = va_arg!(TypeInfo[])(argptr);
    argptr = *cast(void**)argptr;

    if (arguments.length == 2 && arguments[0] is typeid(TypeInfo[]) && 
arguments[1] is typeid(void*))
        resolveArgs(arguments, argptr);
  }
}

void func1(...) {
  resolveArgs(_arguments, _argptr);
  func2(_arguments, _argptr);
}

void func2(...) {
  resolveArgs(_arguments, _argptr);
  // Do something with the args
} 





More information about the Digitalmars-d-learn mailing list