Thread overview | |||||||||
---|---|---|---|---|---|---|---|---|---|
|
May 22, 2005 D(...) to call another D(...) | ||||
---|---|---|---|---|
| ||||
Being a relatively old-timer with D, I feel slightly embarassed about asking this, but I humbly submit: How does one call a variadic-function in D with the variadic arguments presented to the calling function? : int error_log(...) { : return writef(...); : } I seem to have tried all variants of passing combinations of _argptr, _arguments along, with no success. Regards, James Dunne |
May 22, 2005 Re: D(...) to call another D(...) | ||||
---|---|---|---|---|
| ||||
Posted in reply to James Dunne |
Can you actually do this in D ?
In C you woudnt, unless writef has from writef(va_list ap)
error_log(...)
{
writef(va_list ap);
}
:$
On Sun, 22 May 2005 19:34:16 +0000 (UTC)
James Dunne <james.jdunne@gmail.com> wrote:
> Being a relatively old-timer with D, I feel slightly embarassed about asking this, but I humbly submit:
>
> How does one call a variadic-function in D with the variadic arguments presented to the calling function?
>
> : int error_log(...) {
> : return writef(...);
> : }
>
> I seem to have tried all variants of passing combinations of _argptr, _arguments along, with no success.
>
> Regards,
> James Dunne
|
May 22, 2005 Re: D(...) to call another D(...) | ||||
---|---|---|---|---|
| ||||
Posted in reply to James Dunne | There has to be a target method/function signature along the following lines: # void format (TypeInfo[] arguments, va_list argptr) This will accept the implicit parameters _arguments and _argptr of the calling function. I expect std.format does something like this. - Kris "James Dunne" <james.jdunne@gmail.com> wrote in message news:d6qmro$2eh2$1@digitaldaemon.com... > Being a relatively old-timer with D, I feel slightly embarassed about asking > this, but I humbly submit: > > How does one call a variadic-function in D with the variadic arguments presented > to the calling function? > > : int error_log(...) { > : return writef(...); > : } > > I seem to have tried all variants of passing combinations of _argptr, _arguments > along, with no success. > > Regards, > James Dunne |
May 22, 2005 Re: D(...) to call another D(...) | ||||
---|---|---|---|---|
| ||||
Posted in reply to Kris |
nice
On Sun, 22 May 2005 14:21:44 -0700
"Kris" <fu@bar.com> wrote:
> There has to be a target method/function signature along the following lines:
>
> # void format (TypeInfo[] arguments, va_list argptr)
>
> This will accept the implicit parameters _arguments and _argptr of the calling function. I expect std.format does something like this.
>
> - Kris
>
>
> "James Dunne" <james.jdunne@gmail.com> wrote in message news:d6qmro$2eh2$1@digitaldaemon.com...
> > Being a relatively old-timer with D, I feel slightly embarassed about
> asking
> > this, but I humbly submit:
> >
> > How does one call a variadic-function in D with the variadic arguments
> presented
> > to the calling function?
> >
> > : int error_log(...) {
> > : return writef(...);
> > : }
> >
> > I seem to have tried all variants of passing combinations of _argptr,
> _arguments
> > along, with no success.
> >
> > Regards,
> > James Dunne
>
>
|
May 22, 2005 Re: D(...) to call another D(...) | ||||
---|---|---|---|---|
| ||||
Posted in reply to James Dunne | In article <d6qmro$2eh2$1@digitaldaemon.com>, James Dunne says... > >Being a relatively old-timer with D, I feel slightly embarassed about asking this, but I humbly submit: > >How does one call a variadic-function in D with the variadic arguments presented to the calling function? > >: int error_log(...) { >: return writef(...); >: } > >I seem to have tried all variants of passing combinations of _argptr, _arguments along, with no success. > >Regards, >James Dunne James, I know this isn't exactly what you asked for, but since you're going to print the error within the error_log function, it makes sense to me that it should be formatted and then printed there. So maybe the code I wrote below might do the job for your current problem. # // errorlog.d # private import std.stdio; # private import std.format; # private import std.utf; # # uint error_log(...) # { # char[] s; # dchar[] ds; # # void add2Buffer( in dchar dc ) # { # ds.length = ds.length + 1; # ds[ ds.length - 1 ] = dc; # } # # std.format.doFormat( &add2Buffer, _arguments, _argptr ); # # s.length = ds.length; # s = std.utf.toUTF8(ds); # # writef(s); # return s.length; # } # # int main() # { # int iMsgLen; # # iMsgLen = error_log("error: Found ", 123.45, # ", was expecting a non-floating point number."); # writefln(); # writefln("iMsgLen=%d", iMsgLen); # return 0; # } Output: --------- C:\dmd>dmd errorlog.d C:\dmd\bin\..\..\dm\bin\link.exe errorlog,,,user32+kernel32/noi; C:\dmd>errorlog error: Found 123.45, was expecting a non-floating point number. iMsgLen=63 C:\dmd> Hope you find the code useful, David L. ------------------------------------------------------------------- "Dare to reach for the Stars...Dare to Dream, Build, and Achieve!" ------------------------------------------------------------------- MKoD: http://spottedtiger.tripod.com/D_Language/D_Main_XP.html |
May 23, 2005 Re: D(...) to call another D(...) | ||||
---|---|---|---|---|
| ||||
Posted in reply to James Dunne | James Dunne wrote: > Being a relatively old-timer with D, I feel slightly embarassed about asking > this, but I humbly submit: > > How does one call a variadic-function in D with the variadic arguments presented > to the calling function? <snip> Known issue. 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 the 'group where everyone may benefit. |
May 23, 2005 Re: D(...) to call another D(...) | ||||
---|---|---|---|---|
| ||||
Posted in reply to Kris | > # void format (TypeInfo[] arguments, va_list argptr)
Maybe this can be changed to use the newly added Box?
void format( Box[] arguments );
Which means:
* Box[] can be created implicitely when calling a function with ... :
format(2,3,"test") will created a Box[] with 3 elements and passing it to
format(...)
* a Box[] can be passed to a function for the "..."
my_format( ... ) { format(arguments); }
L.
|
Copyright © 1999-2021 by the D Language Foundation