www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - What prevents ImportC from using .h directly?

reply Chris Piker <chris hoopjump.com> writes:
Hi D

Import D is working quite well so far.  One limitation is that 
module definitions require a tiny *.c file which is often just:
```C
#include <libheader.h>
```

Creating this file is trivial and has almost no knock-on effects, 
except when dealing with single file programs. I have quite a few 
small utilities with dub headers. It would be handy if I could 
set an import path and use ImportC on the header file directly, 
skipping the small C file all together.  A specific example in my 
case follows.

Given a C-lib interface defined in the header file:
```
/usr/include/cspice/SpiceUsr.h
```

it would be neat if a dub header similar to the following worked:
```d

/+ dub.sdl:
    name "some_app"
    cImportPaths "/usr/local/include/cspice"
+/

import SpiceUsr;

// ... source continues
```

So, why does ImportC need *.c files exclusively?  I'm sure it 
solves a problem, but I don't know what that problem is.
May 12
parent Nick Treleaven <nick geany.org> writes:
On Sunday, 12 May 2024 at 21:34:30 UTC, Chris Piker wrote:
 So, why does ImportC need *.c files exclusively?  I'm sure it 
 solves a problem, but I don't know what that problem is.
Support for headers has been worked on, but had to be reverted: https://issues.dlang.org/show_bug.cgi?id=23479
May 13