//----
import std.string;
void main()
{
auto a = iota(0, 10);
auto p = &a;
writefln("%s", a);
writefln("%s", p);
}
//----
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
//----
This is not documented behavior. The documented behavior is simply:
"Pointers are formatted as hex integers."
The current behavior (pointer to ranges prints the range) makes no sense to me, and I don't see why a pointer to such a type would get a special treatment.
I think this behavior is wrong, and should be removed to simply treat the pointer as a pointer.
Comment #1 by dmitry.olsh — 2013-12-19T14:01:16Z
(In reply to comment #0)
> This is not documented behavior. The documented behavior is simply:
> "Pointers are formatted as hex integers."
The fun is that a pointer to a range is a range. It naturally supports all of primitives.
> I think this behavior is wrong, and should be removed to simply treat the
> pointer as a pointer.
Maybe.
Comment #2 by monarchdodra — 2013-12-19T14:09:07Z
(In reply to comment #1)
> (In reply to comment #0)
>
> > This is not documented behavior. The documented behavior is simply:
> > "Pointers are formatted as hex integers."
>
> The fun is that a pointer to a range is a range. It naturally supports all of
> primitives.
Almost ;)
https://d.puremagic.com/issues/show_bug.cgi?id=11779
//----
import std.string;
void main()
{
auto a = iota(0, 10).array();
auto p = &a;
writefln("%s", a);
writefln("%s", p);
}
//----
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
7FFF0ABA5FA0
//----
Comment #3 by monarchdodra — 2013-12-19T14:12:51Z
(In reply to comment #1)
> (In reply to comment #0)
>
> > This is not documented behavior. The documented behavior is simply:
> > "Pointers are formatted as hex integers."
>
> The fun is that a pointer to a range is a range. It naturally supports all of
> primitives.
Also (but off topic here), while the slicing operator is still supported, the slice-able *trait* becomes lost, as the returned type (R) won't match the used type (R*).
Comment #4 by acehreli — 2014-12-11T07:20:53Z
This bug made it more difficult for me to debug a separate issue because I could not print addresses of struct objects. I had to figure out this bug first.
Comment #5 by dlang-bot — 2019-12-06T20:39:03Z
@berni44 created dlang/phobos pull request #7305 "Fix Issue 11782 - format pointer to range prints range" fixing this issue:
- Fix Issue 11782 - format pointer to range prints range
https://github.com/dlang/phobos/pull/7305
Comment #6 by dlang-bot — 2019-12-13T06:33:20Z
dlang/phobos pull request #7305 "Fix Issue 11782 - format pointer to range prints range" was merged into master:
- 738d15df38c2459381b89fac1a17f4b3fe2f6f14 by Bernhard Seckinger:
Fix Issue 11782 - format pointer to range prints range
https://github.com/dlang/phobos/pull/7305