So what does happen?

To give all of these generated functions unique names, compilers that work with generics use a process called name mangling (or name munging). This creates a unique name for each internally created function that takes generic parameters.

For which one to use, during linking, the linker analyzes the code signatures required. If the linker sees a signature requiring f32 for T, that munged name object code is included in the final object list. Once the linker has finished with the analysis, the unused objects (those not on the final list) are stripped out. The final binary therefore only contains the required code and not every variation of the types possible.

While different compilers treat generics differently, the process for compilation, name munging, and then final stripping is common among them all!
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset