www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - .di "header" files

reply e-t172 <idontlikespam nospam.com> writes:
Hello,

I'm a bit confused about what the -H option of the DMD compiler (or the
-fintfc of the GDC compiler) actually does. As a matter of fact, I think
of it as a way to automatically generate the equivalent of .h files in
D, which contains only declarations, not the actual code.

So, considering the following code:

module ditest;

import std.stdio;

class Foo
{
         void bar()
         {
                 // Moo.
                 writefln("Hello World !");
         }
}

If I compile that with the -H (or the -fintfc) option (dmd -c -H
ditest.d), I would expect to find something like this in the 
automatically generated .di file:

// D import file generated from 'test.d'
module ditest;
class Foo
{
     void bar();
}

But instead, here is what DMD generates (GDC does the same):

// D import file generated from 'test.d'
module ditest;
import std.stdio;
class Foo
{
     void bar()
{
writefln("Hello World !");
}
}

I must say I don't understand how this is useful : all it did was strip
comments and whitespaces. It didn't strip the body of the bar() 
function, which is what was expected.

So is this normal, if it is, what is the real purpose of the -H option, 
and otherwise, how do I make it work correctly ?

Regards,
Nov 14 2007
parent Frits van Bommel <fvbommel REMwOVExCAPSs.nl> writes:
e-t172 wrote:
[[ .di file includes function body ]]
 
 I must say I don't understand how this is useful : all it did was strip
 comments and whitespaces. It didn't strip the body of the bar() 
 function, which is what was expected.
 
 So is this normal, if it is, what is the real purpose of the -H option, 
 and otherwise, how do I make it work correctly ?

IIRC one purpose of "header" files is improve compilation times without changing the results of those compilations. That requires (small) functions that might be inlined to keep their bodies. "Bigger" functions should have their bodies removed.
Nov 14 2007