www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 2398] New: writef("%x") for a pointer is always uppercase

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2398

           Summary: writef("%x") for a pointer is always uppercase
           Product: D
           Version: 1.035
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Phobos
        AssignedTo: bugzilla digitalmars.com
        ReportedBy: clugdbug yahoo.com.au


prints ABCD, expect abcd. It's treating %x as if it were %X.
Applies to function pointers as well as data pointers.
Applies to writefln as well as writef.
Applies to DMD2.019 also.

This behaviour occurs because of line 794 of format.d, which sets uppercase to
1:
            case Mangle.Tpointer:
                vnumber = cast(ulong)va_arg!(void*)(argptr);
---->           uc = 1;
                flags |= FL0pad;


I can't see any reason for it, and I can't see this behaviour documented
anywhere (the docs for %x say that it must be an integral type, which isn't
true in this case).

FIX: remove line 794. Possibly adjust the docs for %x/%X, to state that "%x/%X
may be used for pointer types".

---
import std.stdio;

void main()
{
    uint *q = cast(uint *)0xabcd;
    writef("%x", q);
}


-- 
Oct 07 2008
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2398


Gide Nwawudu <gide nwawudu.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |patch, spec, wrong-code
                 CC|                            |gide nwawudu.com




--- Comment #1 from Gide Nwawudu <gide nwawudu.com>  2009-05-14 04:16:19 PDT ---
Maybe the current functionality exists because pointers are normally output in
uppercase.
    writefln("%#x", cast(uint*)0xabcd); // -> 0xABCD
    writefln("%#X", cast(uint*)0xabcd); // -> 0XABCD

%x as lowercase and %X as uppercase makes more sense.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 14 2009
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2398





--- Comment #2 from Don <clugdbug yahoo.com.au>  2009-05-14 04:40:57 PDT ---
(In reply to comment #1)
 Maybe the current functionality exists because pointers are normally output in
 uppercase.
     writefln("%#x", cast(uint*)0xabcd); // -> 0xABCD
     writefln("%#X", cast(uint*)0xabcd); // -> 0XABCD
 
 %x as lowercase and %X as uppercase makes more sense.

I think it happened because uppercase is a sensible default for pointers (eg, if printed with %s). BUT, %x should override that default. It's a simple bug. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
May 14 2009
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2398


Don <clugdbug yahoo.com.au> changed:

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




--- Comment #3 from Don <clugdbug yahoo.com.au>  2009-07-16 08:26:04 PDT ---
Fixed in svn 1239 & 1240.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jul 16 2009