Library standardization

Walter Bright newshound1 at digitalmars.com
Sun Apr 20 11:45:49 PDT 2008


Edward Diener wrote:
> Is there an example of code separated into "headers" and 
> "implementation" ? I do not realize how this can be done. Can one just 
> declare a D function or class in a "header" and then import that file 
> and provide an implementation for what had previously just been declared 
> ? What about templates ? I do not see how a D template can just be 
> declared in one .d file and then implemented in another .d file.
> 
> Where in the documentation are .di files described ? I recall reading 
> something about .di files somewhere, probably in the spec, but I can no 
> longer find it.

All .di files are are files with the function bodies removed, i.e.:

int foo() { return 3; }

becomes:

int foo();

There is a compiler switch to generate these files automatically, -H, 
but they can be done manually.

As in C++, templates cannot be compiled without their bodies, so the 
bodies of the templates are not stripped.

The main difference with C++ is you don't *need* to generate those 
header files, the compiler is just fine reading the implementation files 
and extracting what it needs. The .di files are used when desiring to 
hide the implementation, or for speeding up the compilation.



More information about the Digitalmars-d mailing list