D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 11782 - format pointer to range prints range
Summary: format pointer to range prints range
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: All All
: P2 normal
Assignee: No Owner
URL:
Keywords: pull
Depends on:
Blocks:
 
Reported: 2013-12-19 13:56 UTC by monarchdodra
Modified: 2020-03-21 03:56 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description monarchdodra 2013-12-19 13:56:13 UTC
//----
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 Dmitry Olshansky 2013-12-19 14:01:16 UTC
(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 monarchdodra 2013-12-19 14:09:07 UTC
(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 monarchdodra 2013-12-19 14:12:51 UTC
(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 Ali Cehreli 2014-12-11 07:20:53 UTC
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 Dlang Bot 2019-12-06 20:39:03 UTC
@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 Dlang Bot 2019-12-13 06:33:20 UTC
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