variadic function: passing args

icee icee_member at pathlink.com
Tue Jul 4 22:01:27 PDT 2006


In article <e8db27$1hu9$2 at digitaldaemon.com>, Walter Bright says...
>
>icee wrote:
>> is there a way to pass the ... args from one variadic function to another
>> variadic function?
>> 
>> consider such case:
>> void vf1(int a, ...) {
>> 
>> vf2(...);
>> }
>> void vf2(...) {
>> }
>> 
>> can vf2 take _arguments and _argptr from vf1?
>
>No, it works a lot like printf/vprintf. Check out the source to 
>std.format for how to do it.


----------------------
Yes, it works if we explicitly pass _arguments and _argptr to a overloaded ones,
but it would be sweet if the compiler can do a magic for me, by some special
syntax. And even more sometime we have no control on the src which provides the
vf2.

we can do this for a type safe variadic function in D(or C#?):
void vf1(int a, Object[] args...){
vf2(args);
}

and in Python by pack/unpack:
def vf1(a, *args, **kw):
vf2(*arg, **kw)
return

----------------------


In article <e8dc2l$1jta$1 at digitaldaemon.com>, Chris Nicholson-Sauls says...
>
>Maybe if we /did/ have a way it would be better.  Maybe something like:
># vf2(_arguments ... _argptr);
>
>Where the '...' in this case has become an operator meaning to pass these varargs to the 
>callee as such.  Not sure if it'd be the best syntax, but its the simplest thing that 
>comes to mind.
>
>-- Chris Nicholson-Sauls

----------------------------
maybe just vf2(...); is OK??? if this tell the compiler wrap the _arguments
_argptr pair of vf1 into the vf2 and call it???


and maybe i'm asking for too much:)





More information about the Digitalmars-d mailing list