How does the process of building (compiling and linking) source code in D differ from C/C++ especially with regards to inline functions, D's module system (instead of headers) and build tools. How are template instantiations reused in D?
Asked
Active
Viewed 195 times
6
-
1I would imagine that template instantiations are reused in D in very much the same way as extern templates work in C++11. That's about all I can contribute to this discussion. – Mikael Persson Jan 07 '13 at 22:12
-
I believe in a multiple file compilation, template instantiation are done only once then stored in one of the generated object file. But I'm not sure enough to write an answer. When compiling this way, inline functions always cross modules boundaries, like they would if link-time code generation was used in C++. IMHO! – ponce Jan 07 '13 at 23:12
-
@ponce there is no link time code gen currently only some optimisation – ratchet freak Jan 07 '13 at 23:19
-
A followup question: Should we always separately compile all .d files in a project even for modules that contain templates only? – Nordlöw Jan 08 '13 at 07:20
1 Answers
2
it doesn't differ that much, each module gets compiled to its own obj file which then gets linked together which IIRC isn't that different from C/C++ process
the main difference however lie in that the imports are symbolic instead of C's whole file #include
which eliminates the need to headerfiles (though the option for headerlike .di files is there for closed source APIs)
the templates indeed need to be included in the files available to the compiler though (like they need to be in the header for C++)

ratchet freak
- 47,288
- 5
- 68
- 106