Thread overview | ||||||||
---|---|---|---|---|---|---|---|---|
|
January 30, 2007 [Issue 905] New: printf strangeness | ||||
---|---|---|---|---|
| ||||
http://d.puremagic.com/issues/show_bug.cgi?id=905 Summary: printf strangeness Product: D Version: 1.002 Platform: PC OS/Version: Windows Status: NEW Severity: normal Priority: P2 Component: DMD AssignedTo: bugzilla@digitalmars.com ReportedBy: someanon@yahoo.com $ cat pp.d int main(char[][] args) { int i; ulong addr; for (i = 0; i < 10; i++) { addr = cast(ulong)(&i) + i; addr = ((addr + 3) >> 2) << 2; printf("%d %d %d \n", i, addr, i); } return 0; } $ dmd.exe pp.d g:\project\dmd\bin\..\..\dm\bin\link.exe pp,,,user32+kernel32/noi; $ ./pp.exe 0 1244976 0 1 1244980 0 2 1244980 0 3 1244980 0 4 1244980 0 5 1244984 0 6 1244984 0 7 1244984 0 8 1244984 0 9 1244988 0 (Note the 3rd column, all 0!) -- |
January 30, 2007 Re: [Issue 905] New: printf strangeness | ||||
---|---|---|---|---|
| ||||
Posted in reply to d-bugmail |
> for (i = 0; i < 10; i++) {
> addr = cast(ulong)(&i) + i;
> addr = ((addr + 3) >> 2) << 2;
> printf("%d %d %d \n", i, addr, i);
> }
Can you try this?
printf("%d %lld %d \n", i, addr, i);
the 'll' tells printf about the 'long' type.
if you want to print a pointer type, use %p.
|
January 30, 2007 [Issue 905] printf strangeness | ||||
---|---|---|---|---|
| ||||
Posted in reply to d-bugmail | http://d.puremagic.com/issues/show_bug.cgi?id=905 bugzilla@digitalmars.com changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED Resolution| |INVALID ------- Comment #2 from bugzilla@digitalmars.com 2007-01-29 19:23 ------- Not a bug, a ulong needs to be printed with %llu, not %d. -- |
January 30, 2007 [Issue 905] printf strangeness | ||||
---|---|---|---|---|
| ||||
Posted in reply to d-bugmail | http://d.puremagic.com/issues/show_bug.cgi?id=905 ------- Comment #3 from braddr@puremagic.com 2007-01-29 19:51 ------- In general, you probably shouldn't be using printf unless there's a strong need for it. Use the more typesafe functionality provided by phobos with writef. -- |
January 30, 2007 [Issue 905] printf strangeness | ||||
---|---|---|---|---|
| ||||
Posted in reply to d-bugmail | http://d.puremagic.com/issues/show_bug.cgi?id=905 ------- Comment #4 from afb@algonet.se 2007-01-30 02:39 ------- "Hello World" from DMD 1.0 uses printf. We'll be stuck with it for ages. -- |
January 30, 2007 Re: [Issue 905] printf strangeness | ||||
---|---|---|---|---|
| ||||
Posted in reply to d-bugmail | On Tue, 30 Jan 2007 08:39:43 +0000 (UTC), d-bugmail@puremagic.com wrote: > http://d.puremagic.com/issues/show_bug.cgi?id=905 > > > > > > ------- Comment #4 from afb@algonet.se 2007-01-30 02:39 ------- > "Hello World" from DMD 1.0 uses printf. We'll be stuck with it for ages. Damn! You'd think that Walter would "get it" by now. Repeat after me, "D is not C", "D is not C", "D is not C", ... <G> Sorry Walter, just had to give you another ribbing about this D-wart. -- Derek Parnell |
Copyright © 1999-2021 by the D Language Foundation