Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2008-05

is strnew delphi-compatible?

3 messages · 3 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Klaus Hartnegg

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 strnewnil then
            strmove(strnew,p,len);
       end;

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

regards,
Klaus

Reply by email

Michael Van Canneyt
to Klaus Hartnegg
Klaus Hartnegg wrote 31 lines
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 strnewnil then strmove(strnew,p,len); end; Is the above source only used in Turbo Compatibility Mode, or always? Also in Lazarus?

It should be used in TP mode, it makes no sense to use it in Delphi mode. Actually, this call is very much deprecated.

Michael.

Reply by email

Marco van de Voort
to Klaus Hartnegg: TurboPascal and Delphi differ in the way they do strnew. Delphi allocates additional two…
Show quoted text 10 lines
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.

Note that Delphi stores the size of every allocation at $-4. (and maybe $-2 in 16-bit Delphi). However this is done by the heapmanager, not strnew.

If this is meant, it can still be perfectly compatible.

Reply by email