digitalmars.D.learn - variadic funtions
- Tomas Lindquist Olsen (13/13) Feb 12 2007 Hi all.
- Jarrett Billingsley (34/48) Feb 12 2007 Not with "normal" functions. Usually the convention is to declare "..."...
- Tomas Lindquist Olsen (7/34) Feb 12 2007 Thanx for this I wasn't aware of OutStream.writefx . It will work for me
- Jarrett Billingsley (10/13) Feb 12 2007 You would think that this kind of stuff could be automated. I mean, if ...
- Tomas Lindquist Olsen (4/14) Feb 12 2007 Yeah... It does seem like a "missing" feature.
Hi all.
Does anyone know any tricks for passing all arguments of a variadic function
to another?
void foo(...)
{
        // do something
        bar(...);
}
void bar(...)
{
        writefln(...);
}
Thanx
 Feb 12 2007
"Tomas Lindquist Olsen" <tomas famolsen.dk> wrote in message 
news:eqr8q3$1a4a$1 digitalmars.com...
 Hi all.
 Does anyone know any tricks for passing all arguments of a variadic 
 function
 to another?
 void foo(...)
 {
        // do something
        bar(...);
 }
 void bar(...)
 {
        writefln(...);
 }
 Thanx
Not with "normal" functions.  Usually the convention is to declare "..." and 
"TypeInfo[] arguments, va_list argptr" versions of your function so that 
other variadic funcs can call it, like
void foo(...)
{
    vfoo(_arguments, _argptr);
}
void vfoo(TypeInfo[] arguments, va_list argptr)
{
    vbar(arguments, argptr);
}
void bar(...)
{
    vbar(_arguments, _argptr);
}
void vbar(TypeInfo[] arguments, va_list argptr)
{
    // The only way to do this..
    dout.writefx(arguments, argptr, true);
}
With variadic templates, it becomes much more straightforward, although your 
output code can become bloated:
void foo(T...)(T args)
{
    bar(args);
}
void bar(T...)(T args)
{
    writefln(args);
}
You can also look at std.boxer, though I haven't really seen that many 
people use it for varargs.. 
 Feb 12 2007
Jarrett Billingsley wrote:Not with "normal" functions. Usually the convention is to declare "..." and "TypeInfo[] arguments, va_list argptr" versions of your function so that other variadic funcs can call itGuess that is what I was trying to avoid.void foo(...) { vfoo(_arguments, _argptr); } void vfoo(TypeInfo[] arguments, va_list argptr) { vbar(arguments, argptr); } void bar(...) { vbar(_arguments, _argptr); } void vbar(TypeInfo[] arguments, va_list argptr) { // The only way to do this.. dout.writefx(arguments, argptr, true); }Thanx for this I wasn't aware of OutStream.writefx . It will work for me just fine.With variadic templates, it becomes much more straightforward, although your output code can become bloatedYeah I don't want to go this way. Though it's cool that a tuple can be passed as variadic args. Thanx very much for your reply :)
 Feb 12 2007
"Tomas Lindquist Olsen" <tomas famolsen.dk> wrote in message news:eqr9n4$1a4a$2 digitalmars.com...Guess that is what I was trying to avoid.You would think that this kind of stuff could be automated. I mean, if I'm in a variadic function, and I call another variadic function with '...' in its parameter list, shouldn't that be obvious what I mean? Can't the compiler just go "oh, well I guess I can just forward the _arguments and _argptr params to that variadic function"? It seems like something that would be relatively easy to implement. I don't know, maybe it has something to do with the code generation.Yeah I don't want to go this way. Though it's cool that a tuple can be passed as variadic args.I love tuples so much.
 Feb 12 2007
Jarrett Billingsley wrote:You would think that this kind of stuff could be automated. I mean, if I'm in a variadic function, and I call another variadic function with '...' in its parameter list, shouldn't that be obvious what I mean? Can't the compiler just go "oh, well I guess I can just forward the _arguments and _argptr params to that variadic function"? It seems like something that would be relatively easy to implement. I don't know, maybe it has something to do with the code generation.Yeah... It does seem like a "missing" feature. Though the ABI really doesn't give you a clue. (or I just dont get what "_arguments", "hidden" and "this" mean...)
 Feb 12 2007








 
  
  
  Tomas Lindquist Olsen <tomas famolsen.dk>
 Tomas Lindquist Olsen <tomas famolsen.dk>