[fpc-pascal] Question: range checking for string indexing

Tom Verhoeff T.Verhoeff at tue.nl
Thu Oct 30 12:42:15 CET 2008


On Wed, Oct 29, 2008 at 09:58:10PM +0100, Vinzent Höfler wrote:
> Tom Verhoeff wrote:
>
>> I am surprised that for ShortString, the range is not
>> also 1 <= i <= Length(s).
>>
>> IIRC Turbo Pascal only allowed you to access s[0] when range checking
>> was off, and similarly for s[i] with i > Length(s).
>
> No. See transcript:

That looks rather convincing.

> Borland Pascal  Version 7.0  Copyright (c) 1983,92 Borland International

However, IIRC there were some differences between Borland Pascal
and Turbo Pascal (as it was named before they marketed it as
Borland Pascal).

But my memory may be confusing this with UCSD Pascal (Oh, those days :-).

If find it more important that the rules are clear, than that a specific
behavior is provided.

Nevertheless, this means that AnsiStrings and ShortStrings are slightly
more different than suggested in the documentation.  AnsiString provide
more protection with range checking (also implying that a program that
works will with range checking and ShortStrings, might fail when
using AnsiStrings, even though those are more flexible).

In what way can this information be incorporated into the documentation?
Where should it go?  Can I generate a patch for that?

Thanks,

	Tom
-- 
E-MAIL: T.Verhoeff @ TUE.NL     | Dept. of Math. & Comp. Science
PHONE:  +31 40 247 41 25        | Technische Universiteit Eindhoven
FAX:    +31 40 247 54 04        | PO Box 513, NL-5600 MB Eindhoven
http://www.win.tue.nl/~wstomv/  | The Netherlands



More information about the fpc-pascal mailing list