Generating headers with -H

grauzone none at example.net
Mon Nov 2 11:48:59 PST 2009


Andrei Alexandrescu wrote:
> This question may actually belong in .learn.
> 
> What's exactly eliminated from the header generated with -H? I tried it 
> just now and was surprised to see that the generated .di file includes 
> the function bodies of regular (non-template) functions and methods.
> 
> I was under the impression that generated headers exclude function 
> bodies, and found documentation to support that viewpoint:
> 
> http://www.digitalmars.com/d/2.0/dmd-windows.html#interface_files
> 
> says:
> 
> ============
> A D interface file contains only what an import of the module needs, 
> rather than the whole implementation of that module.
> 
> The advantages of using a D interface file for imports rather than a D 
> source file are:
> 
>     * D interface files are often significantly smaller and much faster 
> to process than the corresponding D source file.
>     * They can be used to hide the source code, for example, one can 
> ship an object code library along with D interface files rather than the 
> complete source code.
> ============
> 
> This strongly suggests that function bodies are eliminated. But what I'm 
> seeing is that pretty much all function bodies are kept (exception: 
> static this() functions are not), and only comments are removed.
> 
> So what's -H really doing?

Quoting from the same link:
"[...] they are not part of the D language. They are a feature of the 
compiler, and serve only as an optimization of the build process."

A compiler specific hack that speeds up the build process. Especially 
notice how it includes inlineable functions by design, which make it 
relatively useless as "library headers".

> 
> Andrei



More information about the Digitalmars-d mailing list