<div dir="auto"><div><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Ben Grasset <<a href="mailto:operator97@gmail.com">operator97@gmail.com</a>> schrieb am Mo., 15. Juli 2019, 23:48:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div dir="ltr">On Mon, Jul 15, 2019 at 5:23 PM Sven Barth via fpc-devel <<a href="mailto:fpc-devel@lists.freepascal.org" target="_blank" rel="noreferrer">fpc-devel@lists.freepascal.org</a>> wrote:<br></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="auto"><div dir="auto">That is exactly what is happening if you have a specialization in multiple units that don't know about each other.</div></div></blockquote><div><br></div><div>At what point are they being removed so that the executable is not comically large, then? Is it on the FPC side, or the linker side? Or a bit of both perhaps?</div></div></div></blockquote></div></div><div dir="auto"><br></div><div dir="auto">They are not removed. At least not in the way you think:</div><div dir="auto"><br></div><div dir="auto"><span style="font-family:sans-serif">Declare a type" TTest = specialize TFPGList<LongInt>;" in two different units (here ugentest1 and ugentest2) and then have the following program:</span><br></div><div dir="auto"><span style="font-family:sans-serif"><br></span></div><div dir="auto"><span style="font-family:sans-serif">=== code begin ===</span></div><div dir="auto"><span style="font-family:sans-serif"><br></span></div><div dir="auto"><span style="font-family:sans-serif">program tgentest;</span></div><div dir="auto"><span style="font-family:sans-serif"><br></span></div><div dir="auto"><span style="font-family:sans-serif">{$mode objfpc} </span></div><div dir="auto"><span style="font-family:sans-serif"><br></span></div><div dir="auto"><span style="font-family:sans-serif">uses</span></div><div dir="auto"><span style="font-family:sans-serif"> ugentest1, ugentest2;</span></div><div dir="auto"><span style="font-family:sans-serif"><br></span></div><div dir="auto"><span style="font-family:sans-serif">begin</span></div><div dir="auto"><span style="font-family:sans-serif"> // TFPGList<>.Assign is a non-virtual method</span></div><div dir="auto"><span style="font-family:sans-serif"> Writeln(HexStr(@ugentest1.TTest.Assign));</span></div><div dir="auto"><span style="font-family:sans-serif"> Writeln(HexStr(@ugentest2.TTest.Assign));</span></div><div dir="auto"><span style="font-family:sans-serif">end. </span></div><div dir="auto"><span style="font-family:sans-serif"><br></span></div><div dir="auto"><span style="font-family:sans-serif">=== code end ===</span></div><div dir="auto"><span style="font-family:sans-serif"><br></span></div><div dir="auto"><span style="font-family:sans-serif">The output will then be two different addresses, thus showing that the code had been generated twice. </span></div><div dir="auto"><span style="font-family:sans-serif"><br></span></div><div dir="auto"><span style="font-family:sans-serif">However the compiler/linker is good at leaving out unused code and in this case only the two Assign specializations are kept as their addresses are taken, everything else is discarded. If you'd change one of the two to another non-virtual method then Assign of the one specialization and the other method of the other specialization would be kept. </span></div><div dir="auto"><span style="font-family:sans-serif"><br></span></div><div dir="auto"><span style="font-family:sans-serif">If you use virtual methods inside generics then things are less likely to be removed. </span></div><div dir="auto"><span style="font-family:sans-serif"><br></span></div><div dir="auto"><span style="font-family:sans-serif">Regards, </span></div><div dir="auto"><span style="font-family:sans-serif">Sven </span></div><div dir="auto"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
</blockquote></div></div></div>