www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Passing variadic arguments through to another variadic function?

reply "Jarrett Billingsley" <kb3ctd2 yahoo.com> writes:
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
next sibling parent reply "Regan Heath" <regan netwin.co.nz> writes:
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
next sibling parent "Jarrett Billingsley" <kb3ctd2 yahoo.com> writes:
"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
prev sibling parent derick_eddington nospam.dot.yahoo.dot.com writes:
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.
Mar 28 2005
prev sibling next sibling parent Stewart Gordon <smjg_1998 yahoo.com> writes:
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. 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
prev sibling parent reply bobef <bobef paintballforce.com> writes:
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
parent reply =?UTF-8?B?QW5kZXJzIEYgQmrDtnJrbHVuZA==?= <afb algonet.se> writes:
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
parent reply bobef <bobef_member pathlink.com> writes:
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
parent =?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= <afb algonet.se> writes:
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
Mar 28 2005