digitalmars.D - Passing variadic arguments through to another variadic function?
- Jarrett Billingsley (4/4) Mar 25 2005 Say I have a function I made which takes a variable number of parameters...
- Regan Heath (9/13) Mar 26 2005 AFAIK not possible.
- Jarrett Billingsley (8/14) Mar 26 2005 Ah crap.
- derick_eddington nospam.dot.yahoo.dot.com (3/16) Mar 28 2005 I'd *love* to have this. I have a few nascent D projects that could rea...
- Stewart Gordon (7/11) Mar 26 2005 Not at the moment.
- bobef (8/14) Mar 28 2005 Here is how I do it (the same way its done in C++ or at least I could
- =?UTF-8?B?QW5kZXJzIEYgQmrDtnJrbHVuZA==?= (18/28) Mar 28 2005 But *please* use the std.stdarg module,
- bobef (8/36) Mar 28 2005 This is from http://www.digitalmars.com/d/function.html
- =?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= (7/15) Mar 28 2005 So, if you want the code to run with D compilers
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?
Mar 25 2005
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
Mar 26 2005
"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.
Mar 26 2005
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:I'd *love* to have this. I have a few nascent D projects that could really use this. This would make D so cool.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
Mar 28 2005
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.
Mar 26 2005
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?
Mar 28 2005
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
Mar 28 2005
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
Mar 28 2005
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: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... --andersThe variadic function information found on: http://www.digitalmars.com/d/function.html is not portable to other D compilers but DMD!
Mar 28 2005