digitalmars.D.learn - Compiling a template
- albertas-jn (3/3) Dec 06 2018 If templates are a compile-time feature and instances of
- Basile B. (3/6) Dec 06 2018 Because to instantiate the source code is still used (-I). Just
- =?UTF-8?Q?Ali_=c3=87ehreli?= (21/24) Dec 06 2018 There is no trace of the template in the library or the object file. You...
- albertas-jn (7/26) Dec 06 2018 I see, what confused me was that if I put main() in a different
- Neia Neutuladh (5/8) Dec 06 2018 You compile files, not individual declarations like a template. If you
If templates are a compile-time feature and instances of templates are generated by compiler at compile time, why is it possible to compile a template definition with dmd -lib or -c?
Dec 06 2018
On Thursday, 6 December 2018 at 22:50:49 UTC, albertas-jn wrote:If templates are a compile-time feature and instances of templates are generated by compiler at compile time, why is it possible to compile a template definition with dmd -lib or -c?Because to instantiate the source code is still used (-I). Just the D interface is even not enough.
Dec 06 2018
On 12/06/2018 02:50 PM, albertas-jn wrote:If templates are a compile-time feature and instances of templates are generated by compiler at compile time, why is it possible to compile a template definition with dmd -lib or -c?There is no trace of the template in the library or the object file. You can investigate the compiled symbols with e.g. the 'nm' tool on Linux systems: // deneme.d: void foo(T)(T t) { import std.stdio; writeln(t); } void main() { // foo(42); } $ dmd deneme.d -lib $ nm deneme.a | grep foo No trace of foo... Now uncomment the line in main and repeat: $ dmd deneme.d -lib $ nm deneme.a | grep foo U _D6deneme__T3fooTiZQhFNfiZv 0000000000000000 W _D6deneme__T3fooTiZQhFNfiZv "W" indicates a definition. Ali
Dec 06 2018
On Friday, 7 December 2018 at 01:21:42 UTC, Ali Çehreli wrote:There is no trace of the template in the library or the object file. You can investigate the compiled symbols with e.g. the 'nm' tool on Linux systems: // deneme.d: void foo(T)(T t) { import std.stdio; writeln(t); } void main() { // foo(42); } $ dmd deneme.d -lib $ nm deneme.a | grep foo No trace of foo... Now uncomment the line in main and repeat: $ dmd deneme.d -lib $ nm deneme.a | grep foo U _D6deneme__T3fooTiZQhFNfiZv 0000000000000000 W _D6deneme__T3fooTiZQhFNfiZv "W" indicates a definition.I see, what confused me was that if I put main() in a different file and $ dmd main.d deneme.a the program compiled properly. Now I realize that in this case deneme.a file was ignored and the source file was used instead. I expected an error. Thank you for your answers.
Dec 06 2018
On Thu, 06 Dec 2018 22:50:49 +0000, albertas-jn wrote:If templates are a compile-time feature and instances of templates are generated by compiler at compile time, why is it possible to compile a template definition with dmd -lib or -c?You compile files, not individual declarations like a template. If you have a source file containing a hundred templates and nothing else, and you compile it, you'll get the same output as if you had an empty source file, byte for byte.
Dec 06 2018