Hiding implementations

Sean Kelly sean at f4.ca
Mon Oct 16 21:40:46 PDT 2006


Note that the auto-generated headers will include the bodies of 
functions eligible for inlining.  So depending on your needs, you may 
want to hand-edit the headers after generation.

Bill Baxter wrote:
> Excellent. Thanks.
> Sometimes it's nice to have header files around just as a quick 
> reference to what's in a big API.  Nice that they can be generated 
> automatically.
> 
> --bb
> 
> Derek Parnell wrote:
>> On Tue, 17 Oct 2006 11:48:23 +0900, Bill Baxter wrote:
>>
>>> Since D has no header files, is it possible to distribute binary-only 
>>> libraries?  With C++ you can ship just header files and compiled 
>>> libs, then the users can see the interface but not the 
>>> implementation.  How can you do that with D?
>>>
>>> --bb
>>
>> D does have 'header' files. By convention they have the suffix ".di" and
>> only contain the interface stuff.
>>
>> For example:
>> Implementation file -- mymod.d
>> // ------ start of file ----------
>> private import std.stdio;
>> void myfunc(int x)
>> {
>>     std.stdio.writefln("The ANSWER is %s", x);
>> }
>> // --------- end of file ----------
>>
>> Interface file -- mymod.di
>> // ------ start of file ----------
>> private import std.stdio;
>> void myfunc(int x);
>> // --------- end of file ----------
>>
>>
>> You compile the implementation file and supply either the object file 
>> or a
>> library containing the object file. You then use it as ...
>>
>>  //--- example  import mymod;
>>  void main() { mymod.myfunc(42); }
>>  // --------- end of file
>>
>>
>>  dmd example.d mymod.di thelibrary.lib
>> You can also generate the header file by doing ...
>>
>>   dmd myfunc.d -H
>>
>> This will create the myfunc.di file for you.
>>



More information about the Digitalmars-d-learn mailing list