www.digitalmars.com         C & C++   DMDScript  

D - printf

reply "Sean L. Palmer" <palmer.sean verizon.net> writes:
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);

Am I being an idiot?

Sean
Apr 18 2003
next sibling parent reply John Reimer <jjreimer telus.net> writes:
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);
 
 Am I being an idiot?
 
 Sean
 
 
Tried it as above on my system and worked fine for me. Used DMD 0.61. -John
Apr 18 2003
parent reply "Luna Kid" <lunakid neuropolis.org> writes:
"John Reimer" <jjreimer telus.net> wrote in message
news:b7ogrh$23g1$2 digitaldaemon.com...
 Sean L. Palmer wrote:

 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);
Tried it as above on my system and worked fine for me. Used DMD 0.61.
John, you mean you actually saw: big hex num = ffffffffffffffff big dec num = 18446744073709551615 Strange. I think, as Helmut wrote, one, indeed, needs to use "ll" instead of "l". (I do use 0.61) Cheers, Sz.
Apr 18 2003
next sibling parent "Luna Kid" <lunakid neuropolis.org> writes:
 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);
Tried it as above on my system and worked fine for me. Used DMD 0.61.
John, you mean you actually saw: big hex num = ffffffffffffffff big dec num = 18446744073709551615 Strange. I think, as Helmut wrote, one, indeed, needs to use "ll" instead of "l". (I do use 0.61)
Which seems wrong, anyhow, I mean. Sz.
Apr 18 2003
prev sibling parent John Reimer <jjreimer telus.net> writes:
Luna Kid wrote:
 "John Reimer" <jjreimer telus.net> wrote in message
 news:b7ogrh$23g1$2 digitaldaemon.com...
 
Sean L. Palmer wrote:


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);
Tried it as above on my system and worked fine for me. Used DMD 0.61.
John, you mean you actually saw: big hex num = ffffffffffffffff big dec num = 18446744073709551615 Strange. I think, as Helmut wrote, one, indeed, needs to use "ll" instead of "l". (I do use 0.61) Cheers, Sz.
oops, you're right. ha ha. Stupid me. :-P I guess I did only see the 32 bit version after all. Thanks, - John
Apr 18 2003
prev sibling next sibling parent reply Helmut Leitner <helmut.leitner chello.at> writes:
"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
Apr 18 2003
parent reply "Sean L. Palmer" <palmer.sean verizon.net> writes:
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
Apr 18 2003
parent reply Helmut Leitner <helmut.leitner chello.at> writes:
"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
Apr 18 2003
next sibling parent reply Jonathan Andrew <Jonathan_member pathlink.com> writes:
"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
Apr 18 2003
next sibling parent "Matthew Wilson" <matthew stlsoft.org> writes:
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
Apr 18 2003
prev sibling parent "Sean L. Palmer" <palmer.sean verizon.net> writes:
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
Apr 19 2003
prev sibling parent Ilya Minkov <midiclub 8ung.at> writes:
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.
Apr 25 2003
prev sibling next sibling parent "Matthew Wilson" <matthew stlsoft.org> writes:
%lld

"Sean L. Palmer" <palmer.sean verizon.net> wrote in message
news:b7odha$21hh$1 digitaldaemon.com...
 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);

 Am I being an idiot?

 Sean
Apr 18 2003
prev sibling next sibling parent "Matthew Wilson" <matthew stlsoft.org> writes:
%lld is the correct one

Actually %ld will work, but truncate, and if you have multiple formatted
expansions within a single block it'll be nasty.



"Sean L. Palmer" <palmer.sean verizon.net> wrote in message
news:b7odha$21hh$1 digitaldaemon.com...
 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);

 Am I being an idiot?

 Sean
Apr 18 2003
prev sibling next sibling parent "Matthew Wilson" <matthew stlsoft.org> writes:
%lld is the correct one

Actually %ld will work, but truncate, and if you have multiple formatted
expansions within a single block it'll be nasty.



"Sean L. Palmer" <palmer.sean verizon.net> wrote in message
news:b7odha$21hh$1 digitaldaemon.com...
 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);

 Am I being an idiot?

 Sean
Apr 18 2003
prev sibling next sibling parent "Nic Tiger" <tiger7 progtech.ru> writes:
Write

printf("big hex num = %llx\n",~0ul);

instead (notice double 'l': %llx)
Since it works in DMC, I think it works in D.

"Sean L. Palmer" <palmer.sean verizon.net> wrote in message
news:b7odha$21hh$1 digitaldaemon.com...
 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);

 Am I being an idiot?

 Sean
Apr 18 2003
prev sibling parent "Walter" <walter digitalmars.com> writes:
"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.
May 25 2003