[fpc-pascal] Why do string indices start at 1, but array indices start at 0?
padovani.r at gmail.com
Fri Oct 21 08:25:08 CEST 2011
2011/10/21 Tomas Hajny <XHajT03 at hajny.biz>
> On 20 Oct 11, at 17:43, Andrew Pennebaker wrote:
> > It's inconsistent and ripe for bugs.
> Array indices may start at any ordinal value (including e.g.
> characters, values of enumerated types, etc.), not just 0. Only
> dynamic arrays always start at 0 because that is how they have been
> "imported" from other languages.
As said by Thomas, I think we will have to get along with string.
However, since I stumbled upon the string mistake more than once, I take
the chance to suggest a way to reduce the likelihood of it.
During compilation, by statically checking the indices used to access the
string, the compiler could fire a warning (or error?) if a string is
I think that most of the times the string happens inside a for loop or
similar, so a good percentage of these mistakes can be caught.
> fpc-pascal maillist - fpc-pascal at lists.freepascal.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the fpc-pascal