April 18, 2003 Re: printf | ||||
---|---|---|---|---|
| ||||
Posted in reply to Helmut Leitner | Awesome. You see, this would be great to have on a webpage somewhere. Along with %.s and everything else that's different from C. It'd be great if it just *knew* it was a 64-bit int automatically, and all you have to specify was the formatting. Sean "Helmut Leitner" <helmut.leitner@chello.at> wrote in message news:3E9FD8CB.3FE42283@chello.at... > > > "Sean L. Palmer" wrote: > > > > Ok, looks like printf is in fact in the stdio module. It's also in object. > > I guess this isn't a problem. > > > > However I seem unable to get printf to print out long (64-bit) ints, either > > in decimal or in hex. > > > > printf("big hex num = %lx\n",~0ul); > > printf("big dec num = %lu\n",~0ul); > > > > I use > printf("TimerCount Start=%lld\n",t1); > > -- > Helmut Leitner leitner@hls.via.at > Graz, Austria www.hls-software.com |
April 18, 2003 Re: printf | ||||
---|---|---|---|---|
| ||||
Posted in reply to Sean L. Palmer | "Sean L. Palmer" wrote: > > Awesome. You see, this would be great to have on a webpage somewhere. Along with %.s and everything else that's different from C. We could write a page <http://www.prowiki.org/wiki4d/wiki.cgi?HowTo/printf> > It'd be great if it just *knew* it was a 64-bit int automatically, and all you have to specify was the formatting. We could write a module for this. If D is any good, it shouldn't be a problem. -- Helmut Leitner leitner@hls.via.at Graz, Austria www.hls-software.com |
April 18, 2003 Re: printf | ||||
---|---|---|---|---|
| ||||
Posted in reply to Helmut Leitner |
>
>"Sean L. Palmer" wrote:
>>
>> Awesome. You see, this would be great to have on a webpage somewhere. Along with %.s and everything else that's different from C.
>
>We could write a page
> <http://www.prowiki.org/wiki4d/wiki.cgi?HowTo/printf>
>
>> It'd be great if it just *knew* it was a 64-bit int automatically, and all you have to specify was the formatting.
>
>We could write a module for this. If D is any good, it shouldn't be a problem.
I think the idea is to have a .toString property for all primitives eventually, so you could just puts() everything concatenated together.
-Jon
|
April 18, 2003 Re: printf | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jonathan Andrew | That would be pretty inefficient, though, so would not be desirable for all applications "Jonathan Andrew" <Jonathan_member@pathlink.com> wrote in message news:b7psur$vhk$1@digitaldaemon.com... > > > > >"Sean L. Palmer" wrote: > >> > >> Awesome. You see, this would be great to have on a webpage somewhere. Along with %.s and everything else that's different from C. > > > >We could write a page > > <http://www.prowiki.org/wiki4d/wiki.cgi?HowTo/printf> > > > >> It'd be great if it just *knew* it was a 64-bit int automatically, and all > >> you have to specify was the formatting. > > > >We could write a module for this. > >If D is any good, it shouldn't be a problem. > > I think the idea is to have a .toString property for all primitives eventually, > so you could just puts() everything concatenated together. > > -Jon > > |
April 19, 2003 Re: printf | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jonathan Andrew | No, that would be a bad idea, since unless it knew ahead of time how big to make the staging area it'd end up allocating lots of memory during the concatenation, and doing more work than it has to. This is what streams are for. Streams != Arrays. Streams are more like a buffered circular queue. .toString is nice to have, also, btw. And some kind of stream that streams into a string (a string "staging area", or string "construction zone", if you will) would be quite handy. But for general I/O you really want a stream. Someone was working on something like this. There's a stream module in Phobos; I remember a long time ago it was broken, but I haven't tried it in ages. Anyone? Sean "Jonathan Andrew" <Jonathan_member@pathlink.com> wrote in message news:b7psur$vhk$1@digitaldaemon.com... > > > > >"Sean L. Palmer" wrote: > >> > >> Awesome. You see, this would be great to have on a webpage somewhere. Along with %.s and everything else that's different from C. > > > >We could write a page > > <http://www.prowiki.org/wiki4d/wiki.cgi?HowTo/printf> > > > >> It'd be great if it just *knew* it was a 64-bit int automatically, and all > >> you have to specify was the formatting. > > > >We could write a module for this. > >If D is any good, it shouldn't be a problem. > > I think the idea is to have a .toString property for all primitives eventually, > so you could just puts() everything concatenated together. > > -Jon |
April 25, 2003 Re: printf | ||||
---|---|---|---|---|
| ||||
Posted in reply to Helmut Leitner | Helmut Leitner wrote:
>>It'd be great if it just *knew* it was a 64-bit int automatically, and all
>>you have to specify was the formatting.
>
>
> We could write a module for this. If D is any good, it shouldn't be a problem.
IIRC, there *is* a typesafe printf replacement in the DLI source written by Burton. It uses a "generic" type (struct with overloadings) to get the arguments. This is not inefficient, since you can make the methods of this type output directly.
I don't remember whether there's any particular support for 64-bit int, it can be included easily anyway. The only problem with this approach is that if you make your own overloaded structs, how do you specify their output method?
Besides, i somehow think efficiency is not that important: look, C++ offers iostreams, and most programmers actually use them, despite their inefficiency. The ones who don't, have their printf still available as they know it. However, i'm pretty much sure, that people really conserned with speed would abandon any varargs function and simply output their text part by part, with simple write or something alike.
An interesting thing to have would be a printf which would allow for changing order of arguments, as it usually differs in various natural languages. This can be accomplished by requiering an associative array indexed by string as a second input. This is not necessarily a consern for Phobos though, unless until it has been actually implemented by a volunteer.
-i.
|
May 25, 2003 Re: printf | ||||
---|---|---|---|---|
| ||||
Posted in reply to Sean L. Palmer | "Sean L. Palmer" <palmer.sean@verizon.net> wrote in message news:b7odha$21hh$1@digitaldaemon.com... > However I seem unable to get printf to print out long (64-bit) ints, either > in decimal or in hex. > > printf("big hex num = %lx\n",~0ul); > printf("big dec num = %lu\n",~0ul); The format for D long's is %lld and %llu. |
Copyright © 1999-2021 by the D Language Foundation