www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - How to redirect variadic function parameters?

reply Mikko <mikko dev.null> writes:
In case I have

void foo(...) {}
void bar(...) {}

how should I call bar from foo and passing along all the parameters?

void foo(...) { bar(?); } // bar(...) doesn't work

thanks, Mikko
Feb 18 2007
parent reply Bill Baxter <dnewsgroup billbaxter.com> writes:
Mikko wrote:
 In case I have
 
 void foo(...) {}
 void bar(...) {}
 
 how should I call bar from foo and passing along all the parameters?
 
 void foo(...) { bar(?); } // bar(...) doesn't work
 
 thanks, Mikko

You have to create a different, non-variadic function that takes _arguments and _argptr as arguments. See for example writefx in phobos/std/stdio.d: void writefx(FILE* fp, TypeInfo[] arguments, void* argptr, int newline=false); Or use variadic templates, which can be passed from one function to another. --bb
Feb 18 2007
parent reply =?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= <afb algonet.se> writes:
Bill Baxter wrote:

 You have to create a different, non-variadic function that takes 
 _arguments and _argptr as arguments.
 
 See for example writefx in phobos/std/stdio.d:
    void writefx(FILE* fp,
                 TypeInfo[] arguments, void* argptr,
                 int newline=false);

The portable version uses "std.stdarg.va_list" instead: void writefx(FILE* fp, TypeInfo[] arguments, va_list argptr, int newline=false); Should be the same for DMD, but is a built-in for GDC. (need to use va_arg, instead of pointer manipulations) --anders http://www.prowiki.org/wiki4d/wiki.cgi?DocComments/Function#PortabilityandVariadicFunctions
Feb 19 2007
next sibling parent reply Robin Allen <r.a3 ntlworld.com> writes:
Anders F Björklund wrote:
 Bill Baxter wrote:
 
 You have to create a different, non-variadic function that takes 
 _arguments and _argptr as arguments.

 See for example writefx in phobos/std/stdio.d:
    void writefx(FILE* fp,
                 TypeInfo[] arguments, void* argptr,
                 int newline=false);

The portable version uses "std.stdarg.va_list" instead: void writefx(FILE* fp, TypeInfo[] arguments, va_list argptr, int newline=false); Should be the same for DMD, but is a built-in for GDC. (need to use va_arg, instead of pointer manipulations) --anders http://www.prowiki.org/wiki4d/wiki.cgi?DocComments/Function#Portability ndVariadicFunctions

Is there any reason why bar(...) couldn't be implemented? It's a mich nicer syntax.
Feb 19 2007
parent "Jarrett Billingsley" <kb3ctd2 yahoo.com> writes:
"Robin Allen" <r.a3 ntlworld.com> wrote in message 
news:erd25h$li1$2 digitalmars.com...
 Is there any reason why bar(...) couldn't be implemented? It's a mich 
 nicer syntax.

I think we had a topic on this not much more than a week ago, and came to much the same conclusion.
Feb 19 2007
prev sibling parent C. Dunn <cdunn2001 gmail.com> writes:
 --anders

Your link does not work. Software error: File-Open-Fehler (/usr/home/wikise/wiki/slurp/163.181.251.9.rl): Disc quota exceeded at /usr/local/etc/httpd/htdocs/prowiki/wiki.cgi line 5351. ----------- Anyway, I need to do this too, but my real question is: How do I turn off dout buffering? Otherwise, I need to redirect writefln(...) to fwritefln(derr,...).
Aug 01 2007