[fpc-pascal] StrToInt is using ShortString buffer?

Michael Van Canneyt michael at freepascal.org
Wed Jan 12 18:37:14 CET 2022

On Wed, 12 Jan 2022, James Richters via fpc-pascal wrote:

> I don’t see what the problem with a shortstring buffer is..  strtoint
> could not make use of an input string longer than 256 characters anyway,
> because the output integer could not have more than 19 digits anyway..  so
> an input string longer than this would be useless… just convert to a
> shortstring and to strtoint.

The "problem" is that IntToStr() gets an Ansistring argument, but uses Val()
to do the actual work, and Val() converts from whatever type you use to
ShortString to do the work.

Hence there is always a conversion AnsiString -> ShortString or (worse) WideString->ShortString
when you call IntToStr() and this is 'slow'.

What Alexey would like to see is that the basic function uses PChar, so that
no conversion is necessary. In that case, only the way in which the Pchar
(pointing to the string content) is passed to this new function will differ 
between AnsiString or ShortString.

In the case when you use widestring, a conversion is always performed.


More information about the fpc-pascal mailing list