A thought on pointers
Carlos Santander
csantander619 at gmail.com
Mon Jun 19 20:03:59 PDT 2006
Tesuji escribió:
> For pointers, using * and & for dereferencing seems ugly, a more interesting
> syntax could be:
>
> A* aPtr;
> A instanceA;
>
> to point aPtr to instanceA, instead of
>
> <code> aPtr = &instanceA; </code>
>
> write
>
> <code> aPtr -> instanceA; </code>
>
> and it reads "aPtr points to instanceA". This frees the pointer syntax up from
> the * & operators,
> Using this syntax, one can eliminate the need for the dereferencing operator
> (*), and use pointers directly with operators etc, i.e.
>
> int i1, i2, i3;
> int* p1, p2, p3;
>
> p1 -> i1;
> p2 -> i2;
> p3 -> i3;
>
> p3 = p1 + p2;
>
> And this has the same effect as i1 = i2 + i3;
Except that sometimes people wants to do pointer arithmetic.
In any case, since C does pointers in this way (like D), it's really unlikely
Walter is going to change it (to give it any hope at all ;).)
> This would largely simplify the coding for containers, and allow a custom
> container to do things like
>
> myVector[3]++;
>
> provided that the opIndex operator for MyVector returns a pointer. Also makes
> the pointer behave much like C++ reference types.
>
>
>
>
--
Carlos Santander Bernal
More information about the Digitalmars-d
mailing list