Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2024-01

IntToStr implementation

10 messages · 6 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Hairy Pixels

Can anyone show me where to find the IntToStr implementation in SysUtils? There's so many level of indirection and macros I have no idea where to look for it!

Regards,
Ryan Joseph

Reply by email

Marco van de Voort
to Hairy Pixels

Op 17-1-2024 om 15:57 schreef Hairy Pixels via fpc-pascal:

Can anyone show me where to find the IntToStr implementation in SysUtils? There's so many level of indirection and macros I have no idea where to look for it!

Grep rtl/objpas/sysutils for it.

sysstr.inc for the implementation sysstrh.inc for the declaration

Reply by email

Benito van der Zander
to Marco van de Voort

Hi,

Show quoted text 6 lines
sysstr.inc for the implementation sysstrh.inc for the declaration function IntToStr(Value: Longint): string; begin System.Str(Value, result); end ;

I doubt that is the actual implementation anyone is looking for

How about this:

Cheers,
Benito

Marco van de Voort wrote 15 lines
Op 17-1-2024 om 15:57 schreef Hairy Pixels via fpc-pascal: > Can anyone show me where to find the IntToStr implementation in > SysUtils? There's so many level of indirection and macros I have no > idea where to look for it! Grep rtl/objpas/sysutils for it. sysstr.inc for the implementation sysstrh.inc for the declaration _______________________________________________ fpc-pascal maillist  - https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply by email

Hairy Pixels
to Marco van de Voort: Op 17-1-2024 om 15:57 schreef Hairy Pixels via fpc-pascal: Grep rtl/objpas/sysutils for…
Show quoted text 11 lines
On Jan 17, 2024, at 10:15 PM, Marco van de Voort via fpc-pascal wrote: Op 17-1-2024 om 15:57 schreef Hairy Pixels via fpc-pascal: > Can anyone show me where to find the IntToStr implementation in SysUtils? There's so many level of indirection and macros I have no idea where to look for it! Grep rtl/objpas/sysutils for it. sysstr.inc for the implementation sysstrh.inc for the declaration

Which then goes to System.Str(), where is that? I found some other Str functions in a lstrings.pas file but I don't think that's it. All the macros break code tools for me and I can't find anything.

Regards,
Ryan Joseph

Reply by email

Sven Barth
to Hairy Pixels

Hairy Pixels via fpc-pascal schrieb am
Do., 18. Jan. 2024, 00:44:

Show quoted text 21 lines
> On Jan 17, 2024, at 10:15 PM, Marco van de Voort via fpc-pascal < > wrote: > > > Op 17-1-2024 om 15:57 schreef Hairy Pixels via fpc-pascal: >> Can anyone show me where to find the IntToStr implementation in SysUtils? There's so many level of indirection and macros I have no idea where to look for it! > > Grep rtl/objpas/sysutils for it. > > > sysstr.inc for the implementation sysstrh.inc for the declaration > Which then goes to System.Str(), where is that? I found some other Str functions in a lstrings.pas file but I don't think that's it. All the macros break code tools for me and I can't find anything.

There is no source for Str() in that sense, because Str() is a compiler intrinsic implemented in the compiler's ninl.pas.

Regards,
Sven

Reply by email

Hairy Pixels
to Sven Barth
On Jan 18, 2024, at 1:51 PM, Sven Barth via fpc-pascal 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.

Regards,
Ryan Joseph

Reply by email

Michael Van Canneyt
to Hairy Pixels
Hairy Pixels wrote 8 lines
> On Jan 18, 2024, at 1:51 PM, Sven Barth via fpc-pascal 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.

Reply by email

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

actual-parameter = expression { ":" expression } . actual-parameter-list = "(" actual-parameter { "," actual-parameter } ")" .

Regards,

Adriaan van Os

Reply by email

Michael Van Canneyt
to Adriaan van Os
Adriaan van Os wrote 7 lines
> Also something which cannot be handled by 'standard' syntax. > (unless you wish to count generics and implicit specialization as "standard > syntax") actual-parameter = expression { ":" expression } . actual-parameter-list = "(" actual-parameter { "," actual-parameter } ")" .

The compiler obviously can parse it.

More accurately, I meant: you cannot write a function declaration to handle that syntax.

procedure Str(O : Integer { what to write here for the :N:M ??? }; var S);

Michael.

Reply by email

Adriaan van Os
to Michael Van Canneyt
Michael Van Canneyt wrote
More accurately, I meant: you cannot write a function declaration to handle that syntax.

It is true that a regular (non-built-in) procedure/function with that syntax can not be declared.

Some more strange ducks

- Exit allowing Program as parameter (UCSD-Pasca)
- Scan allowing a partial-expression as second parameter (UCSD-Pascal) e.g. Scan( -26, =':', S)
- SizeOf allowing a type-identifier as parameter

etcetera.

Regards,

Adriaan van Os

Reply by email