Array Lower Bounds

0ffh frank at frankhirsch.youknow.what.todo.net
Tue Dec 18 15:24:58 PST 2007


Mike Marquard wrote:
> Well one reason is because some people prefer starting arrays at 1 (like
> myself). As for numbers other than 0 or 1, there are situations where
> that makes sense. Right now I am experimenting with an artificial
> intelligence concept of my own in another base zero only language and
> sometimes I'm doing things like copying and processing a portion of an
> image. There have been alot of situations were it would have been nice
> if I could simply have those arrays have starting and ending bounds that
> conform to the portion of the image they represent.

Sorry, IMHO zero-starting arrays are the logically most consistent choice
in a language that also offers pointers, starting at 1 is awkward.

> Obviously this isn't a necesity but it would be a helpfull feature for
> something like that if I decide to rewrite it in d some day.

You could just scrap the extra element and fill your array starting at 1,
if you absolutely must. Check the 0th element for change with asserts or
contracts, to catch errors.

regards, frank


More information about the Digitalmars-d-learn mailing list