[fpc-devel] is strnew delphi-compatible?

Klaus Hartnegg hartnegg at gmx.de
Thu May 8 10:53:25 CEST 2008


Hi,

TurboPascal and Delphi differ in the way they do strnew.
Delphi allocates additional two bytes preceding the first
character to store the length of the string.

The turbo pascal docs say:
The allocated space is StrLen(Str) + 1 bytes long.

The delphi docs say:
A 16-bit number giving the total amount of memory allocated is stored
in the two bytes preceding the first character; it is equal to Size+2.

The file trunk/rtl/inc/strings.pp contains code that looks compatible
with turbo pascal:

     function strnew(p : pchar) : pchar;
       var
          len : SizeInt;
       begin
          strnew:=nil;
          if (p=nil) or (p^=#0) then
            exit;
          len:=strlen(p)+1;
          getmem(strnew,len);
          if strnew<>nil then
            strmove(strnew,p,len);
       end;

Is the above source only used in Turbo Compatibility Mode,
or always? Also in Lazarus?

regards,
Klaus



More information about the fpc-devel mailing list