Can anyone provide an example of how D templates are overridable by global symbols?

H. S. Teoh hsteoh at quickfur.ath.cx
Fri Jan 28 23:43:00 UTC 2022


On Fri, Jan 28, 2022 at 11:01:41PM +0000, Siarhei Siamashka via Digitalmars-d-learn wrote:
[...]
> Internet seems to disagree about what happens when multiple weak
> symbols are encountered and various interpretations can be found:
> "Given multiple weak symbols, choose any of the weak symbols", "if
> there exists several weak symbols, GCC will choose one that have the
> largest size (memory occupation)", etc. And I'm not inclined to
> happily rely on either of these opinions.

You don't have to rely on any opinions. Try it out yourself and find out
for sure. E.g., compile several versions of exactly the same function
(e.g, each printing something different), make sure you mark them as
weak functions and rename the object files into different names.  Link
them all together with another object file that contains main() that
calls the weak symbol. Running the program ought to tell you which
version got linked.  Try linking in different orders (specify the object
files in different orders in your compile/link command) to see what
differences there might be.


T

-- 
Democracy: The triumph of popularity over principle. -- C.Bond


More information about the Digitalmars-d-learn mailing list