[fpc-pascal]Length function on ansistrings

Marco van de Voort marcov at stack.nl
Sat Jan 4 13:20:57 CET 2003


> On Sat, 4 Jan 2003, Peter Vreman wrote:
> 
> > householding.
> 
> To clarify:  AnsiString is defined as a 'silent' pchar :
> a pchar that points to :
> 
>   @-12 : Longint for maximum size;
>   @-8  : Longint for actual size;
>   @-4  : Longint for reference count;
>   @    : String + Terminating #0;
>   Pchar(Ansistring) is a valid typecast.
> 
> The length()  function returns the actual size of the string, at address
> @-8. So strlen(pchar(s)) is not needed at all.
> 
> @-12 is the memory actually allocated on the heap for this string.

And note that it therefore may contain #0's (though whether that is smart is
a different subject).

The #0 is for C compability, to allow casting to pchar.





More information about the fpc-pascal mailing list