Re: Default array base index



On Sun, 27 Jan 2008 11:20:59 -0800 (PST), Scott Burson wrote:

I just came across this Wikipedia page:

http://en.wikipedia.org/wiki/Comparison_of_programming_languages_%28array%29

which claims that the default base index for arrays in Ada is 1. It
has been over 15 years since I have written any Ada, so my memory is
fuzzy, but what I recall is that there actually is no default: the
base index must always be specified explicitly when the array is
declared.

Actually both statements are wrong. As an example consider:

Foo : array (Character) of Boo;

Here the base index is neither specified nor 1. It is NUL (character).

However, it does appear that Ada culture leans toward the
use of 1 as a default (for example, the language numbers the
dimensions of the array from 1 in attribute expressions).

Maybe, when index is a signed integer type. But with modular integer types
0 as the lower bound looks quite natural. And for enumeration types the
issue makes no sense anyway.

What Ada culture leans toward is actually designing programs so that this
question would become irrelevant. An array of fixed size is defined over a
type or subtype which bounds determine the array bounds, so that there are
no illegal indices at all.

--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de
.



Relevant Pages

  • Re: Default array base index
    ... Foo: array of Boo; ... Here the base index is neither specified nor 1. ... Hmm, I would say it is specified explicitly but indirectly, via the ... when index is a signed integer type. ...
    (comp.lang.ada)
  • Re: Answer to why low and high are bad !
    ... > any extra computation at run time, only one addition at compile time. ... Given an array with a base index of 5 a reference such as A has to be ...
    (alt.comp.lang.borland-delphi)
  • Default array base index
    ... I just came across this Wikipedia page: ... which claims that the default base index for arrays in Ada is 1. ... dimensions of the array from 1 in attribute expressions). ...
    (comp.lang.ada)
  • Re: Answer to why low and high are bad !
    ... Unless you actually do a wierd thing such as offset the array starting ... >>any extra computation at run time, only one addition at compile time. ... > load i ... > With a zero base index array the process has one less computation ...
    (alt.comp.lang.borland-delphi)
  • Re: 10 rules for benchmarking (was Re: Teaching new tricks to an old dog (C++ -->Ada))
    ... so I did the same in Ada, results are in the T and TC columns. ... array are used, ... I take it you mean the one best performing assembly language ... that a given assembly language program cannot be beaten by ...
    (comp.programming)