Thread overview | |||||||
---|---|---|---|---|---|---|---|
|
February 13, 2007 variadic funtions | ||||
---|---|---|---|---|
| ||||
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 |
February 13, 2007 Re: variadic funtions | ||||
---|---|---|---|---|
| ||||
Posted in reply to Tomas Lindquist Olsen | "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.. |
February 13, 2007 Re: variadic funtions | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jarrett Billingsley | 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 it > Guess 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 bloated Yeah 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 :) |
February 13, 2007 Re: variadic funtions | ||||
---|---|---|---|---|
| ||||
Posted in reply to Tomas Lindquist Olsen | "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. |
February 13, 2007 Re: variadic funtions | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jarrett Billingsley | 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...)
|
Copyright © 1999-2021 by the D Language Foundation