www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Why is std.string.format a c-style variadic function?

reply Andrej Mitrovic <andrej.mitrovich gmail.com> writes:
I'm only asking because I can't use it inside of a pragma(msg) call
since CTFE can't do C-style variadic functions yet. Is `format`
defined this way for performance reasons? (to avoid template bloat?)
Sep 25 2011
next sibling parent reply Jacob Carlborg <doob me.com> writes:
On 2011-09-26 05:39, Andrej Mitrovic wrote:
 I'm only asking because I can't use it inside of a pragma(msg) call
 since CTFE can't do C-style variadic functions yet. Is `format`
 defined this way for performance reasons? (to avoid template bloat?)

std.string.format is using a D-style variadic parameter list. This would be a C-style variadic parameter list: extern (C) string format (int c, ...); It might just be an old function from D1 when template tuple parameters where not just that much. -- /Jacob Carlborg
Sep 25 2011
next sibling parent reply Ellery Newcomer <ellery-newcomer utulsa.edu> writes:
On 09/26/2011 07:42 AM, Andrej Mitrovic wrote:
 On 9/26/11, Jacob Carlborg <doob me.com> wrote:
 std.string.format is using a D-style variadic parameter list.

The compiler disagrees with you: D:\DMD\dmd2\windows\bin\..\..\src\phobos\std\string.d(2432): Error: function std.string.format C-style variadic functions are not yet implemented in CTFE L2432: string format(...) I don't see any other format() overloads in std.string.

std.metastrings.Format wouldn't be what you want, would it?
Sep 26 2011
parent reply Ellery Newcomer <ellery-newcomer utulsa.edu> writes:
On 09/26/2011 11:15 AM, Andrej Mitrovic wrote:
 On 9/26/11, Ellery Newcomer <ellery-newcomer utulsa.edu> wrote:
 std.metastrings.Format wouldn't be what you want, would it?

Yep it is, Jonathan mentioned it above.

thunderbird hates me. second time I give an answer made redundant by orphaned subthread. I'll counter by giving random unsolicited thoughts on Format: don't use it for codegen (or any long format strings, I suppose). dmd chokes on it very quickly. format specifiers could use positional parameters or something. Last summer I actually wrote a Replace template to scratch that itch. dmd choked on it pretty quickly too.
Sep 26 2011
next sibling parent travert phare.normalesup.org (Christophe) writes:
Ellery Newcomer , dans le message (digitalmars.D.learn:29819), a écrit :
 On 09/26/2011 11:15 AM, Andrej Mitrovic wrote:
 On 9/26/11, Ellery Newcomer <ellery-newcomer utulsa.edu> wrote:
 std.metastrings.Format wouldn't be what you want, would it?

Yep it is, Jonathan mentioned it above.

thunderbird hates me. second time I give an answer made redundant by orphaned subthread.

I've got the same problem with most of Jonathan's posts. I use flrn, an obsure news reader that nobody here probably knows about, so I thought it was just me. It seems that the Reference field in Jonathan's posts are unusual and break threads in some news reader. Would anyone know a solution (either for Elley and me, or for Jonathan)? -- Christophe
Sep 27 2011
prev sibling parent Dmitry Olshansky <dmitry.olsh gmail.com> writes:
On 27.09.2011 4:43, Ellery Newcomer wrote:
 On 09/26/2011 11:15 AM, Andrej Mitrovic wrote:
 On 9/26/11, Ellery Newcomer<ellery-newcomer utulsa.edu>  wrote:
 std.metastrings.Format wouldn't be what you want, would it?

Yep it is, Jonathan mentioned it above.

thunderbird hates me. second time I give an answer made redundant by orphaned subthread.

 I'll counter by giving random unsolicited thoughts on Format:

 don't use it for codegen (or any long format strings, I suppose). dmd
 chokes on it very quickly.

 format specifiers could use positional parameters or something. Last
 summer I actually wrote a Replace template to scratch that itch. dmd
 choked on it pretty quickly too.

-- Dmitry Olshansky
Sep 27 2011
prev sibling parent Jacob Carlborg <doob me.com> writes:
On 2011-09-26 17:12, Steven Schveighoffer wrote:
 On Mon, 26 Sep 2011 08:42:09 -0400, Andrej Mitrovic
 <andrej.mitrovich gmail.com> wrote:

 On 9/26/11, Jacob Carlborg <doob me.com> wrote:
 std.string.format is using a D-style variadic parameter list.

The compiler disagrees with you: D:\DMD\dmd2\windows\bin\..\..\src\phobos\std\string.d(2432): Error: function std.string.format C-style variadic functions are not yet implemented in CTFE L2432: string format(...) I don't see any other format() overloads in std.string.

That's likely a bug. D variadic functions push the TypeInfo of each parameter onto the stack as well as the parameters themselves. Unfortunately, it's probably just a wrong error message, I doubt D variadic parameters are supported in CTFE. -Steve

Yes, that is not a C-style variadic function. -- /Jacob Carlborg
Sep 26 2011
prev sibling next sibling parent Andrej Mitrovic <andrej.mitrovich gmail.com> writes:
On 9/26/11, Jacob Carlborg <doob me.com> wrote:
 std.string.format is using a D-style variadic parameter list.

The compiler disagrees with you: D:\DMD\dmd2\windows\bin\..\..\src\phobos\std\string.d(2432): Error: function std.string.format C-style variadic functions are not yet implemented in CTFE L2432: string format(...) I don't see any other format() overloads in std.string.
Sep 26 2011
prev sibling next sibling parent "Steven Schveighoffer" <schveiguy yahoo.com> writes:
On Mon, 26 Sep 2011 08:42:09 -0400, Andrej Mitrovic  
<andrej.mitrovich gmail.com> wrote:

 On 9/26/11, Jacob Carlborg <doob me.com> wrote:
 std.string.format is using a D-style variadic parameter list.

The compiler disagrees with you: D:\DMD\dmd2\windows\bin\..\..\src\phobos\std\string.d(2432): Error: function std.string.format C-style variadic functions are not yet implemented in CTFE L2432: string format(...) I don't see any other format() overloads in std.string.

That's likely a bug. D variadic functions push the TypeInfo of each parameter onto the stack as well as the parameters themselves. Unfortunately, it's probably just a wrong error message, I doubt D variadic parameters are supported in CTFE. -Steve
Sep 26 2011
prev sibling next sibling parent Andrej Mitrovic <andrej.mitrovich gmail.com> writes:
On 9/26/11, Ellery Newcomer <ellery-newcomer utulsa.edu> wrote:
 std.metastrings.Format wouldn't be what you want, would it?

Yep it is, Jonathan mentioned it above.
Sep 26 2011
prev sibling parent Andrej Mitrovic <andrej.mitrovich gmail.com> writes:
Hmm yea, the docs say so too. Sorry for the noise then. :)
Sep 26 2011