are mixin string templates with functions removed?

John Colvin john.loughran.colvin at gmail.com
Thu Aug 1 11:06:36 PDT 2013


On Thursday, 1 August 2013 at 17:57:28 UTC, JS wrote:
> On Thursday, 1 August 2013 at 17:53:38 UTC, Ali Çehreli wrote:
>> On 08/01/2013 10:45 AM, H. S. Teoh wrote:
>>> On Thu, Aug 01, 2013 at 07:12:51PM +0200, John Colvin wrote:
>>>> On Thursday, 1 August 2013 at 17:09:07 UTC, JS wrote:
>>>>> If I have a bunch of templates that are only used for code
>>>>> generation, are they removed in the binary(since they are 
>>>>> not
>>>>> needed)?
>>>>
>>>> templates don't exist in binaries.
>>>
>>> Templates are like cookie molds, you use them to generate 
>>> lots of
>>> (almost) identical cookies, but you never serve the mold to 
>>> the
>>> customer. ;-)
>>>
>>>
>>> T
>>>
>>
>> I think the question is whether the instantiations of such 
>> templates are removed. If the instance is used only to 
>> initialize an enum, the function shouldn't stay in the binary.
>>
>> Even if the function remains, I think the linker takes care of 
>> removing unused functions.
>>
>> Ali
>
> I have a lot of code generation templates(only for code). I 
> want to make sure they don't hang around in the binary(even 
> strings they use) as there is no point and it is potentially 
> dangerous(security issues).

The linker will get rid of anything not needed. Marking things as 
package (or more restrictive) will make sure they don't stay in 
librarys when not used.

Ultimately, if you're worried about it, get the linker to print a 
list of all functions, or check the assembly.


More information about the Digitalmars-d-learn mailing list