D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 8531 - formatting string documentation
Summary: formatting string documentation
Status: RESOLVED INVALID
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: All All
: P2 normal
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-08-10 03:39 UTC by bioinfornatics
Modified: 2012-10-27 09:26 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description bioinfornatics 2012-08-10 03:39:04 UTC
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 hsteoh 2012-10-27 09:04:03 UTC
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 Kenji Hara 2012-10-27 09:26:22 UTC
(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"