digitalmars.D - A thought on pointers
- Tesuji (24/24) Jun 19 2006 For pointers, using * and & for dereferencing seems ugly, a more interes...
- Carlos Santander (6/46) Jun 19 2006 Except that sometimes people wants to do pointer arithmetic.
-
Stewart Gordon
(6/19)
Jun 26 2006
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.
Jun 19 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
Jun 19 2006
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.
Jun 26 2006