Thread overview | |||||
---|---|---|---|---|---|
|
June 20, 2006 A thought on pointers | ||||
---|---|---|---|---|
| ||||
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; 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. |
June 20, 2006 Re: A thought on pointers | ||||
---|---|---|---|---|
| ||||
Posted in reply to Tesuji | 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 |
June 26, 2006 Re: A thought on pointers | ||||
---|---|---|---|---|
| ||||
Posted in reply to Tesuji | Tesuji wrote:
> 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>
<snip>
If you want Fortran, you know where to find it.
Moreover, the -> notation will just confuse people coming from C(++), where it has a completely different meaning.
Stewart.
|
Copyright © 1999-2021 by the D Language Foundation