Deimos (How to port a header)

Jacob Carlborg doob at me.com
Thu Jan 31 23:24:03 PST 2013


On 2013-01-31 21:42, Marco Leise wrote:
> Maybe Deimos (the GitHub presence) could use a dry piece of
> text that explains how to convert a header. I have just had
> the need for xcb for example, but no idea how a good header
> translation is supposed to look like, if all files need to be
> converted already on the first go and other questions, like if
> all functions should be marked nothrow for example.

There's a tool, DStep, that can automatically translate C headers to D 
modules. It will require some manual adjustments, like adding imports:

https://github.com/jacob-carlborg/dstep

These contain some info about porting a C header to a D module:

http://dlang.org/interfaceToC.html
http://dlang.org/htod.html

There's also a series of blog post about porting creating bindings to C 
libraries, which I cannot find right now.

> Also it looks like a long on Windows is 32-bit while on Linux
> it depends on the machine word size and libraries like xcb use
> "architecture dependent includes" for whatever that means in
> praxis.

The size of "long" depends on what data model is used. To simplify, on 
Windows, "long" is always 32bit. On the rest of the platforms "long" is 
32 bit when compiling for a 32bit platform and 64 bit when compiling for 
a 64bit platform.

To be more precise:

http://en.wikipedia.org/wiki/64-bit_computing#64-bit_data_models

-- 
/Jacob Carlborg


More information about the Digitalmars-d-learn mailing list