Re: [fpc-pascal] Procedural generics question

2020-08-26 Thread Nico Neumann via fpc-pascal
The TypeInfo function checks the code during run-time thus the generated code is 'bloated'. Better use the compiler intrinsic GetTypeKind. {$mode objfpc} uses typinfo; generic procedure Add; begin if GetTypeKind(T) = tkInteger then WriteLn('an integer'); if GetTypeKind(T) = tkString t

Re: [fpc-pascal] Procedural generics question

2020-08-26 Thread Ryan Joseph via fpc-pascal
> On Aug 26, 2020, at 5:44 PM, Nico Neumann via fpc-pascal > wrote: > > generic procedure Add; > begin > if GetTypeKind(T) = tkInteger then WriteLn('an integer'); > if GetTypeKind(T) = tkString then WriteLn('a string'); > end; Question for the compiler team why doesn't the "is" operat

Re: [fpc-pascal] Procedural generics question

2020-08-26 Thread Sven Barth via fpc-pascal
Am 26.08.2020 um 14:59 schrieb Ryan Joseph via fpc-pascal: On Aug 26, 2020, at 5:44 PM, Nico Neumann via fpc-pascal wrote: generic procedure Add; begin if GetTypeKind(T) = tkInteger then WriteLn('an integer'); if GetTypeKind(T) = tkString then WriteLn('a string'); end; Question fo

Re: [fpc-pascal] Procedural generics question

2020-08-26 Thread Sven Barth via fpc-pascal
Am 25.08.2020 um 23:47 schrieb Benito van der Zander via fpc-pascal: Hi, that is generating rather odd code (r40721) project1.lpr:9    begin 00401090 55   push   %rbp 00401091 4889e5   mov    %rsp,%rbp 00401094

Re: [fpc-pascal] Procedural generics question

2020-08-26 Thread Ryan Joseph via fpc-pascal
> On Aug 27, 2020, at 3:49 AM, Sven Barth wrote: > >> if T is integer then >> ; >> >> and get something which is well optimized. > Because there was simply no need for this. Since the introduction of generics this would be a nice extension to add for the is operator. Regards, Ryan