Semantics of toString
Leandro Lucarella
llucax at gmail.com
Fri Nov 6 07:05:03 PST 2009
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
-----------------------
--
Leandro Lucarella (AKA luca) http://llucax.com.ar/
----------------------------------------------------------------------
GPG Key: 5F5A8D05 (F8CD F9A7 BF00 5431 4145 104C 949E BFB6 5F5A 8D05)
----------------------------------------------------------------------
Vaporeso, al verse enfundado por la depresión, decide dar fin a su vida
tomando Chinato Garda mezclado con kerosene al 50%. Ante el duro trance
pierde la movilidad en sus miembros derechos: inferior y superior. En
ese momento es considerado como el hombre líder del movimiento de
izquierda de Occidente.
More information about the Digitalmars-d
mailing list