Bug 2398 – writef("%x") for a pointer is always uppercase

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
phobos
Product
D
Version
D1 (retired)
Platform
x86
OS
Windows
Creation time
2008-10-07T03:47:00Z
Last change time
2014-03-01T00:36:47Z
Keywords
patch, spec, wrong-code
Assigned to
bugzilla
Creator
clugdbug

Comments

Comment #0 by clugdbug — 2008-10-07T03:47:40Z
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); }
Comment #1 by gide — 2009-05-14T04:16:19Z
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.
Comment #2 by clugdbug — 2009-05-14T04:40:57Z
(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.
Comment #3 by clugdbug — 2009-07-16T08:26:04Z
Fixed in svn 1239 & 1240.