Bug 905 – printf strangeness

Status
RESOLVED
Resolution
INVALID
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D1 (retired)
Platform
x86
OS
Windows
Creation time
2007-01-29T18:25:00Z
Last change time
2014-02-16T15:22:15Z
Assigned to
bugzilla
Creator
someanon

Comments

Comment #0 by someanon — 2007-01-29T18:25:53Z
$ 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!)
Comment #1 by benoit — 2007-01-29T19:10:25Z
> 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.
Comment #2 by bugzilla — 2007-01-29T19:23:40Z
Not a bug, a ulong needs to be printed with %llu, not %d.
Comment #3 by braddr — 2007-01-29T19:51:05Z
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.
Comment #4 by afb — 2007-01-30T02:39:38Z
"Hello World" from DMD 1.0 uses printf. We'll be stuck with it for ages.