Which type it better to use for array's indices?

ref2401 via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Dec 4 05:24:16 PST 2015


Which type it better to use for array's indices?

float[] arr = new float[10];
int i;
long j;		
size_t k;
// which one is better arr[i], a[j]or arr[k] ?

It seem like `size_t` suites well because 'is large enough to 
represent an offset into all addressible memory.' 
(http://dlang.org/spec/type.html#size_t)
However sometimes I want index to be less the 0 to represent a 
particular case.
For instance `find(float[] arr, float v)` may return -1 if `v` 
has not been found.

Again which type is better or put it into another words which 
type should I pick as default?

Thank you.


More information about the Digitalmars-d-learn mailing list