Proof of concept: automatically import C header files

Timothee Cour thelastmammoth at gmail.com
Tue Jul 16 20:49:19 PDT 2013


On Tue, Jul 16, 2013 at 8:05 AM, Dicebot <public at dicebot.lv> wrote:

> On Tuesday, 16 July 2013 at 14:15:55 UTC, Jacob Carlborg wrote:
>
>> Made a proof of concept to automatically parse, translate and import C
>> header files in D using DStep. DMD is linked against DStep and does not
>> start new process to make the translation.
>>
>
> While this a relatively common request, I don't think such stuff belongs
> to compiler. It creates extra mandatory dependencies while providing little
> advantage over doing this as part of a build system.
>
> So far I am perfectly satisfied with invoking dstep from a Makefile.
>

I agree that this stuff doesn't belong to compiler, however Makefiles suck
(not even portable) and build systems should be avoided whenever a more
integrated solution exist.

So how about a library solution instead, which doesn't require compiler
change:

----
import parse_c_header_importer;
mixin(parse_c_header(import("foo.h")));
void main () { foo();}
----

There are several options:

A)
mixin(parse_c_header(import("foo.h"))); => defines D symbols for everything
in foo.h (excluding things included by it)

B)
mixin(parse_c_header(import("foo.h"),recursive)); => same, but recursively
(probably not very useful, but could be useful if we instead used .i swig
interface files.

C)
The least wasteful:
void foo();
int bar();
mixin(parse_c_header(import("foo.h"),foo,bar));
=> only defines symbols provided

(I've proposed this syntax in an earlier thread)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20130716/5f1a0534/attachment.html>


More information about the Digitalmars-d mailing list