Thread overview | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
|
March 26, 2005 Passing variadic arguments through to another variadic function? | ||||
---|---|---|---|---|
| ||||
Say I have a function I made which takes a variable number of parameters, and I want to pass those through to something like std.string.format. Is this even possible? Is there a way to reconstruct the "..." from the _arguments and _argptr arrays? |
March 26, 2005 Re: Passing variadic arguments through to another variadic function? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jarrett Billingsley | On Fri, 25 Mar 2005 20:48:20 -0500, Jarrett Billingsley <kb3ctd2@yahoo.com> wrote:
> Say I have a function I made which takes a variable number of parameters,
> and I want to pass those through to something like std.string.format. Is
> this even possible? Is there a way to reconstruct the "..." from the
> _arguments and _argptr arrays?
AFAIK not possible.
What we need I suspect is a feature/construct from Walter. Something that allows:
- simple pass thru of arguments.
- addition of arguments.
- re-order/insert/remove of arguments.
Regan
|
March 26, 2005 Re: Passing variadic arguments through to another variadic function? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Regan Heath | "Regan Heath" <regan@netwin.co.nz> wrote in message news:opsn8tmxmv23k2f5@nrage.netwin.co.nz... > AFAIK not possible. > > What we need I suspect is a feature/construct from Walter. Something that allows: > > - simple pass thru of arguments. > - addition of arguments. > - re-order/insert/remove of arguments. Ah crap. Looking at the disassembly for calling variadic functions, it looks as though the compiler just makes the two arrays and passes them to the function. So I suppose it wouldn't be too much of a step to allow us to "override" the default compiler behavior of automatically creating the arrays for us. |
March 26, 2005 Re: Passing variadic arguments through to another variadic function? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jarrett Billingsley | Jarrett Billingsley wrote: > Say I have a function I made which takes a variable number of parameters, and I want to pass those through to something like std.string.format. Is this even possible? Is there a way to reconstruct the "..." from the _arguments and _argptr arrays? Not at the moment. http://www.digitalmars.com/drn-bin/wwwnews?digitalmars.D/11282 Stewart. -- My e-mail is valid but not my primary mailbox. Please keep replies on on the 'group where everyone may benefit. |
March 28, 2005 Re: Passing variadic arguments through to another variadic function? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jarrett Billingsley | Here is how I do it (the same way its done in C++ or at least I could not come with better idea):
int foo(...) {return fooA(_argptr,_arguments);}
int fooA(void *args,TypeInfo[] argtypes)
{
//deal with it the same way as if you got ...
}
Jarrett Billingsley wrote:
> Say I have a function I made which takes a variable number of parameters, and I want to pass those through to something like std.string.format. Is this even possible? Is there a way to reconstruct the "..." from the _arguments and _argptr arrays?
>
>
|
March 28, 2005 Re: Passing variadic arguments through to another variadic function? | ||||
---|---|---|---|---|
| ||||
Posted in reply to bobef | bobef wrote: > Here is how I do it (the same way its done in C++ or at least I could not come with better idea): > > int foo(...) {return fooA(_argptr,_arguments);} > > int fooA(void *args,TypeInfo[] argtypes) > { > //deal with it the same way as if you got ... > } But *please* use the std.stdarg module, and type "va_list" instead of "void *": > alias void* va_list; The variadic function information found on: http://www.digitalmars.com/d/function.html is not portable to other D compilers but DMD! _arguments has the type va_list, not void*. Can't say I recommend renaming them, either ? (better to use the standard arguments/argptr) int foo(...) {return fooA(_arguments, _argptr);} int fooA(TypeInfo[] arguments, va_list argptr); It would be even better if the missing TypeInfo for e.g. pointers could be added, so it worked... (currently all pointers get "anonymous" TypeInfo) There is also no (portable) way of adding or removing arguments from the variadic list that was passed in. A problem for printf-style functions: "(char[], ...)" --anders |
March 28, 2005 Re: Passing variadic arguments through to another variadic function? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Anders F Björklund | This is from http://www.digitalmars.com/d/function.html ..argptr, which is a void* pointer... from context ..Variadic functions have a special local variable declared for them, _argptr, which is a void* pointer to the first of the variadic arguments. To access the arguments, _argptr must be cast to a pointer to the expected argument type... In article <d28mp1$1k1q$1@digitaldaemon.com>, =?UTF-8?B?QW5kZXJzIEYgQmrDtnJrbHVuZA==?= says... > >bobef wrote: >> Here is how I do it (the same way its done in C++ or at least I could not come with better idea): >> >> int foo(...) {return fooA(_argptr,_arguments);} >> >> int fooA(void *args,TypeInfo[] argtypes) >> { >> //deal with it the same way as if you got ... >> } > >But *please* use the std.stdarg module, >and type "va_list" instead of "void *": > >> alias void* va_list; > >The variadic function information found on: >http://www.digitalmars.com/d/function.html >is not portable to other D compilers but DMD! > >_arguments has the type va_list, not void*. >Can't say I recommend renaming them, either ? >(better to use the standard arguments/argptr) > >int foo(...) {return fooA(_arguments, _argptr);} >int fooA(TypeInfo[] arguments, va_list argptr); > > >It would be even better if the missing TypeInfo >for e.g. pointers could be added, so it worked... >(currently all pointers get "anonymous" TypeInfo) > >There is also no (portable) way of adding or removing >arguments from the variadic list that was passed in. >A problem for printf-style functions: "(char[], ...)" > >--anders |
March 28, 2005 Re: Passing variadic arguments through to another variadic function? | ||||
---|---|---|---|---|
| ||||
Posted in reply to bobef | bobef wrote: >>But *please* use the std.stdarg module, >>and type "va_list" instead of "void *": > This is from http://www.digitalmars.com/d/function.html > > ..argptr, which is a void* pointer... That's true, in DMD. Here is what I wrote: >>The variadic function information found on: >>http://www.digitalmars.com/d/function.html >>is not portable to other D compilers but DMD! So, if you want the code to run with D compilers others that the ones from Digital Mars (e.g. GDC), please use std.stdarg, and va_list instead of (void*) ? Hopefully Walter will fix the doc page above soon... --anders |
March 29, 2005 Re: Passing variadic arguments through to another variadic function? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Regan Heath | In article <opsn8tmxmv23k2f5@nrage.netwin.co.nz>, Regan Heath says... > >On Fri, 25 Mar 2005 20:48:20 -0500, Jarrett Billingsley <kb3ctd2@yahoo.com> wrote: >> Say I have a function I made which takes a variable number of parameters, and I want to pass those through to something like std.string.format. Is this even possible? Is there a way to reconstruct the "..." from the _arguments and _argptr arrays? > >AFAIK not possible. > >What we need I suspect is a feature/construct from Walter. Something that allows: > >- simple pass thru of arguments. >- addition of arguments. >- re-order/insert/remove of arguments. > >Regan I'd *love* to have this. I have a few nascent D projects that could really use this. This would make D so cool. |
Copyright © 1999-2021 by the D Language Foundation