4

I've just read this, and I'm a little confused about what D interface files can and can't contain. That page isn't terribly clear about that (although it spends time explaining their benefits).

5
  • Did you see the third paragraph? They can be generated from regular D files with the -H switch. Aug 1, 2014 at 23:59
  • So basically, .di files are just D files which I run differently through the compiler?
    – Koz Ross
    Aug 2, 2014 at 0:00
  • From reading the description in your link, it looks like .di files are what .h files are for C. They define the contents of a module, without the implementation. Aug 2, 2014 at 0:01
  • "D interface files can be created by the compiler from a D source file by using the -H switch to the compiler. D interface files have the .di file extension. When the compiler resolves an import declaration, it first looks for a .di D interface file, then it looks for a D source file. D interface files bear some analogous similarities to C++ header files. But they are not required in the way that C++ header files are, and 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."
    – Bauss
    Aug 2, 2014 at 12:42
  • That quote is misleading as you MUST provide a .di file with your (closed source) library.
    – DejanLekic
    Aug 4, 2014 at 8:13

1 Answer 1

7

.di and .d files are identical as far as the compiler is concerned. (literally, it treats both exactly the same as D source).

You can put as much or as little as you want in them, as long as the interface is indeed compatible with the library code. It is your responsibility to keep the interfaces in sync - if you change a function signature in the main library code, you must change it (or regenerate the .di from the main .d file) in the interface too, the compiler will not check them for you.

I don't use .di files personally, I think their only practical benefit is if you are writing a closed source library.

1
  • Thanks - love your new book on D, by the way.
    – Koz Ross
    Aug 7, 2014 at 4:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.