[fpc-pascal] AnsiString

David Emerson dle3ab at angelbase.com
Tue Jan 25 20:23:36 CET 2011


Luis Fernando Del Aguila Mejía wrote:
> The documentation 
> (http://www.freepascal.org/docs-html/prog/progsu146.html#x189-1990008.2.7) 
> says:
>     -8 Longint current string with size.
>     -4 Longint with reference count.
>  But, when I want access to that structure, I have to do it backwards.
>    -8 Longint with reference count.
>    -4 Longint current string with size.

> Do these positions are different, depending on microprocessor being used ?

I'm fairly certain that is an error in the documentation, and that it SHOULD 
always be as you discovered it to actually be.


As an aside, a tip for doing pointer arithmetic...

var
  s : ansistring;
  p : ptruint;

p := pointer(s);
dec(p);  // equivalent to p:=p-4 because p is a typed pointer.

Using typed pointers in this way will likely make it easier to adapt your code 
to a 64-bit conversion in the future.

Also note that, in this case, dec(p,2) would do p:=p-8, as (hopefully) expected

I use these types of constructs frequently, and it makes it much easier to 
change types, if that is ever necessary, or adapt constructs to new types.

Cheers,
David




More information about the fpc-pascal mailing list