How do I implement a simple generic Max function in Free Pascal 3.2.2. Here is my attempt so far:
File: cmn.pas
interface
...
generic function Max<U>(a, b: U): U;
generic function Min<U>(a, b: U): U;
...
implementation
...
generic function Max<U>(a, b: U): U;
begin
if a < b then
begin
Exit(b);
end
else
begin
Exit(a);
end;
end;
generic function Min<U>(a, b: U): U;
begin
if b < a then
begin
Exit(b);
end
else
begin
Exit(a);
end;
end;
This fails with the following compiler error:
Free Pascal Compiler version 3.2.2 [2021/05/16] for x86_64
Copyright (c) 1993-2021 by Florian Klaempfl and others
Target OS: Linux for x86-64
Compiling ./exm.pas
Compiling cmn.pas
exm.pas(19,15) Error: Generics without specialization cannot be used as a type for a variable
exm.pas(19,43) Error: Generics without specialization cannot be used as a type for a variable
exm.pas(34) Fatal: There were 2 errors compiling module, stopping
Fatal: Compilation aborted
Error: /home/sg/temp/pascal/bin/ppcx64 returned an error exitcode