[fpc-pascal] IntToStr implementation

Michael Van Canneyt michael at freepascal.org
Thu Jan 18 10:13:27 CET 2024



On Thu, 18 Jan 2024, Hairy Pixels via fpc-pascal wrote:

>
>
>> On Jan 18, 2024, at 1:51 PM, Sven Barth via fpc-pascal <fpc-pascal at lists.freepascal.org> wrote:
>> 
>> There is no source for Str() in that sense, because Str() is a compiler intrinsic implemented in the compiler's ninl.pas.
>> 
>
> Well that explains everything now! What is this an intrinsic? I was curious how it was implemented and now I'm even more curious.

I asked myself the same question.

The reason is it needs to support the same syntax as Write(ln) for padding the output:

Str(I:N:M,S);

This is not a "standard" syntax and needs to be handled specially by the compiler.

Additionally, Str() can be used to convert an enum to a string value:

Type
   TMyEnum = (one,two,three);

var
   M : TMyEnum = one;
   S : String;

begin
   Str(M,S);
end.

Also something which cannot be handled by 'standard' syntax.
(unless you wish to count generics and implicit specialization as "standard syntax")

Michael.


More information about the fpc-pascal mailing list