[fpc-pascal]ansistring question

Peter Vreman peter at freepascal.org
Fri Jan 3 20:03:14 CET 2003


> MY question is...does FPC in fact do this?  In my example, a and b DO
> point to the same ansistring structure, because b := a.
>
> Peter Vremen has answered my question:
>
>> Yes.
>
> And I am delighted with Peter's answer, but concerned that the two of
> you gave opposite answers.

To take away you concern, here is the source of the compare routine:
Function fpc_AnsiStr_Compare(const S1,S2 : AnsiString):
Longint;[Public,Alias : 'FPC_ANSISTR_COMPARE'];  {$ifdef hascompilerproc}
c
{
  Compares 2 AnsiStrings;
  The result is
   <0 if S1<S2
   0 if S1=S2
   >0 if S1>S2
}
Var
  MaxI,Temp : Longint;
begin
  if pointer(S1)=pointer(S2) then
   begin
     fpc_AnsiStr_Compare:=0;
     exit;
   end;
  Maxi:=Length(S1);
  temp:=Length(S2);
  If MaxI>Temp then
   MaxI:=Temp;
  Temp:=CompareByte(S1[1],S2[1],MaxI);
  if temp=0 then
   temp:=Length(S1)-Length(S2);
  fpc_AnsiStr_Compare:=Temp;
end;






More information about the fpc-pascal mailing list