[fpc-pascal] Question: range checking for string indexing
Frank Peelo
f26p at eircom.net
Thu Oct 30 17:51:30 CET 2008
Tom Verhoeff wrote:
> 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).
IIRC the differences were in how big a program you could write.
Accessing the length byte in a string did not change.
[digs out an old copy of Turbo.com -- TurboPascal version 3. Amazingly,
it will run under WinXP.]
var
x : String[50];
i : Integer;
Begin
x := 'Hello, World';
for i := 0 to length(x) do
write(ord(x[i]),' ');
writeln;
x[0] := #5;
writeln(x);
end.
Outputs this:
12 72 101 108 108 111 44 32 87 111 114 108 100
Hello
so read and write access to element 0
More information about the fpc-pascal
mailing list