D as an extension language for C
jmh530
john.michael.hall at gmail.com
Tue May 16 14:50:04 UTC 2023
On Monday, 15 May 2023 at 19:13:49 UTC, Walter Bright wrote:
> On 5/15/2023 5:20 AM, jmh530 wrote:
>> importC lets you import .c file in D, but not a .h file. To
>> import a .h file in D, I have to create a .c file and include
>> only the .h file header and then import the .c file. Would you
>> be able to streamline that further so that the .h file can be
>> imported?
>
> The .h file limitation is due to a disagreement between myself
> and Iain about the best way forward for it.
I hope some agreement is reached.
Looking over the (multiple) github discussions, I was partial to
the solution of `import "foo.h"` combined with a custom search
path for `.h` files [1]. The one to use `import("foo.h")` looks a
bit too much like an import expression.
You made a comment about the import syntax getting kludged [2],
but it would be a little less kludge-y if you could import any
file like `import "foo.d"` or `import "foo.c"`, but then only
allow .d/.c/.i files to be imported like `import foo`. Further, I
recall you previously commenting on how sometimes you have to
make the compiler more complicated in order to make things work
how users expect them to. This might be a situation like that.
Though I can't say what the best solution is, I think most would
agree that it would be good to have something better than
creating a .c file to import a .h file.
Not a lot of code has been written yet that uses importC so there
is still time to get it right.
[1] https://github.com/dlang/dmd/pull/14700
[2]
https://github.com/dlang/dmd/pull/14864#issuecomment-1432256522
More information about the Digitalmars-d
mailing list