Array Lower Bounds
Bill Baxter
dnewsgroup at billbaxter.com
Tue Dec 18 12:12:07 PST 2007
Jarrett Billingsley wrote:
> "bearophile" <bearophileHUGS at lycos.com> wrote in message
> news:fk8ips$1jt$1 at digitalmars.com...
>> Mike Marquard:
>>> I know the default starting index for arrays is zero in D. But is there
>>> any way you can change the lower bounds to something other zero? For
>>> instance having the index go from 1 to 10 or say 100 to 200.
>> Delphi, TurboPascal, and probably FreePascal have such feature, and once
>> in a while it's useful, see here for example:
>> http://blogs.warwick.ac.uk/mtcharemza/entry/fortran_9095_versus_1
>> but it's not difficult to adapt your mind to the fixed 0 starting point,
>> and you don't need to go looking at definition of the array type every
>> time to see what's the actual starting point of the array you want to use.
>
> Thankfully D has slices and value types with overloadable indexing operators
> (though, as noted, without ref returns you can't *perfectly* emulate
> built-in arrays, though that will change), making it possible to emulate
> this rather .. niche feature.
It's not so niche I don't think. It's pretty widely used in numerical
computing. It's just a question of whether it's useful enough to
warrant the extra syntactical and memory baggage it would require. I
think it would require all arrays to carry around a third value, no?
--bb
More information about the Digitalmars-d-learn
mailing list