Compiling a template
Ali Çehreli
acehreli at yahoo.com
Fri Dec 7 01:21:42 UTC 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
More information about the Digitalmars-d-learn
mailing list