[fpc-pascal] Strings
Marco van de Voort
marcov at stack.nl
Tue Jul 16 14:02:35 CEST 2013
In our previous episode, Carsten Bager said:
> Function Sum(p:pointer; len:LongInt):LongInt;
> Type
> a_typ=array[0..pred(maxLongInt)] of byte;
> a=^a_typ;
> var
> i:LongInt;
> Begin
> result:=0;
> for i:=0 to len do
> result:=result+a(p)^[i];
> End;
0..len is len+1 items.
>
> Procedure test;
> Var
> s:ansistring;
> i:integer;
> Begin
> s:='Something';
> for i:=0 to 100000 do
> s:=s+'Test';
> if Sum(@s[1],length(s)) = 0 then
s[1] length(s) implies "lenght(s)" items. IOW the sum routine also
adds/accesses the final zero.
More information about the fpc-pascal
mailing list