Alternatives to pointers?

Timon Gehr timon.gehr at gmx.ch
Sat Sep 30 08:27:26 UTC 2017


On 29.09.2017 03:51, Jerry wrote:
> I miss ref variables, for the simple fact that using the square brackets 
> with a ref variable doesn't access the pointer. Don't know how many 
> times I've accidentially used a pointer as an array. Not very easy to 
> catch especially if the object has pointers to other objects of the same 
> type. Possibly adding something like this, if ref variables are off the 
> table?
> 
> @noarray int* value;
> value[x] = 10; // compile error, pointer is not an array.

void main()@safe{
     int x;
     int* value;
     value[x]=10;
}

Error: safe function 'D main' cannot index pointer 'value'


More information about the Digitalmars-d mailing list