[fpc-pascal] Best integer type to be used for string indexes

Michael Van Canneyt michael at freepascal.org
Sun Jun 19 11:28:22 CEST 2011

On Sat, 18 Jun 2011, Vladimir Zhirov wrote:

> Hi,
> Reviewing a bunch of my string processing functions
> made me wonder what integer type should I use for
> position / length parameters.
> I used to plain "Integer" for this task, but looking through
> RTL and LCL code I noticed that sometimes SizeInt and
> even PtrInt are also used:
> - Length, Copy use Integer;
> - Pos, Delete, Insert use SizeInt;
> - UTF8Length, UTF8Pos, UTF8Copy, etc. use PtrInt.
> PtrInt use seems to be generally discouraged by FPC docs
> but does it apply to this particular case?
> The only benefit I see in SizeInt/PtrInt is larger size on 64-bit
> targets, that should theoretically make it possible to index
> larger strings. But is AnsiString type capable of holding more
> than High(Integer) bytes, or will it be so in the future?

Ansistring is not capable of keeping more than High(Integer) bytes.

> Thus, the question basically is: what integer type
> is recommended to be used as index/length
> for future-proof string processing functions?

SizeInt should do just fine.


More information about the fpc-pascal mailing list