Bug 8531 – formatting string documentation

Status
RESOLVED
Resolution
INVALID
Severity
normal
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-08-10T03:39:00Z
Last change time
2012-10-27T09:26:22Z
Assigned to
nobody
Creator
bioinfornatics

Comments

Comment #0 by bioinfornatics — 2012-08-10T03:39:04Z
Dear, In this documentation http://dlang.org/phobos/std_format.html#format-string They do not talk about %u for unsigned number. %u works well with both readf and writef
Comment #1 by hsteoh — 2012-10-27T09:04:03Z
Actually, I think %u is redundant. std.format uses compile-time introspection to do the "right thing" for %d. You can pass an unsigned number for %d and it works correctly. I just tested %u, it seems that it's just an alias for %d: int a = -10; writefln("%u", a); // outputs "-10" So I think this bug is invalid.
Comment #2 by k.hara.pg — 2012-10-27T09:26:22Z
(In reply to comment #1) > Actually, I think %u is redundant. std.format uses compile-time introspection > to do the "right thing" for %d. You can pass an unsigned number for %d and it > works correctly. I just tested %u, it seems that it's just an alias for %d: > > int a = -10; > writefln("%u", a); // outputs "-10" > > So I think this bug is invalid. Yes. And, if programmer really want to format int value as unsigned, he needs to use cast instead of %u. writefln("%d", cast(uint)a); // outputs "4294967286"