opStar

Janice Caron caron800 at googlemail.com
Sun Nov 11 15:54:11 PST 2007


On 11/11/07, Bill Baxter <dnewsgroup at billbaxter.com> wrote:
> First, let's call it opDeref

Good plan!


> 1) In D, the magic pointer dereferencing will only dereference one
> level.

If possible, I'd like to go the other way, and have both opStar AND
implicit dereferencing * for pointers recurse as many times as
required. So, if p were a pointer to a pointer to a struct then
p.member would be equivalent to (*p).member, which would in turn be
equivalent to (**p).member. Likewise, opDeref could be repeatedly
applied until you reach a type which has no opDeref and isn't a
pointer.

There is some justification for this. In C++, that's operator-> is
applied recursively until you read a type which has operator-> and
isn't a pointer. It makes perfect sense in D not only because we use .
instead of ->, but because otherwise, what would you have opStar
return? We can't return references, remember. So should opDeref()
return by value an entire struct, if the struct is large? I think it
just needs to return a pointer, and then rely on the language to do
the additional dereference.




> 2) Make a special property that if used disables the opDeref.  Maybe
> even x.this.member could be used for that.  Actually, I think because of
> 1) that should work automatically if x is a struct.

Ooh, I like that. So x.this.member never calls opDeref. Simple.
Elegant. Perfect!



More information about the Digitalmars-d mailing list