Semantics of toString

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Fri Nov 6 07:57:19 PST 2009


Leandro Lucarella wrote:
> Andrei Alexandrescu, el  6 de noviembre a las 08:50 me escribiste:
>>> So, type specification is important. Variables reordering is important
>>> too, and you even have it in POSIX's printf():
>>>
>>> 	printf("%1$d:%2$.*3$d:%4$.*3$d\n", hour, min, precision, sec);
>>>
>>> (see http://www.opengroup.org/onlinepubs/9699919799/functions/printf.html)
>>>
>>> I like printf()'s format (I don't know if it's just because I'm used to it
>>> though :).
>>>
>> I think you found a bug in Phobos. I tried this:
>>
>> import std.stdio;
>>
>> void main() {
>>     int hour = 1, min = 2, precision = 2, sec = 3;
>>     writef("%1$d:%2$.*3$d:%4$.*3$d\n", hour, min, precision, sec);
>> }
>>
>> and it prints
>>
>> 1:002:003
>>
>> But it should really print:
>>
>> 1:02:03
>>
>> right?
> 
> Yes.
> 
> ------------------------
> $ cat t.c
> #include <stdio.h>
> 
> int main() {
> 	int hour = 1, min = 2, precision = 2, sec = 3;
> 	printf("%1$d:%2$.*3$d:%4$.*3$d\n", hour, min, precision, sec);
> 	return 0;
> }
> 
> $ make t
> cc     t.c   -o t
> $ ./t
> 1:02:03
> -----------------------
> 

Thanks!

http://d.puremagic.com/issues/show_bug.cgi?id=3479

Andrei



More information about the Digitalmars-d mailing list