www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 905] New: printf strangeness

reply d-bugmail puremagic.com writes:
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!)


-- 
Jan 29 2007
next sibling parent "Frank Benoit (keinfarbton)" <benoit tionex.removethispart.de> writes:
   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.
Jan 29 2007
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=905


bugzilla digitalmars.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |INVALID





Not a bug, a ulong needs to be printed with %llu, not %d.


-- 
Jan 29 2007
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=905






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.


-- 
Jan 29 2007
prev sibling parent reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=905






"Hello World" from DMD 1.0 uses printf. We'll be stuck with it for ages.


-- 
Jan 30 2007
parent Derek Parnell <derek psych.ward> writes:
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
 
 
 
 
 

 "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
Jan 30 2007