[fpc-devel] Packages, Generics

Florian Klaempfl florian at freepascal.org
Mon Sep 13 10:36:19 CEST 2010


> 
> I don't know whether it is still the case but there was a time the 'is'
> operator relied on RTTI. So as soon as you have two different RTTI
> entries for, e.g., TMyList<integer> (which could happen if you compile
> with packages) the operator needs some 'repair'. 

This is why FPC has specialize (to emphasis this): only class instances
having the same specialized generic type are considered being equal:
type
   TList1 = specialize TList<Longint>;
   TList2 = specialize TList<Longint>;

var
  l1a,l1b : TList1;
  l2 : TList2;

Only l1a and l1b are assignment compatible. This is like records or
classes are handled in pascal: even records with exactly the same fields
are not assignment compatible.

So generics in packages are a non issue for fpc: every package
specializes the generics created by the units contained in the package
as it is done currently by a program: the specialization and code
generation for all generics specialized by a program and its units is
done during compilation of the program. For packages, it is just done
during package compilation.





More information about the fpc-devel mailing list