C Interoperability

Generate Bindings

D can link with C libraries very easily. However, the header files must be converted into D bindings.

Ideally, we could generate bindings from C header files automatically. In practice, you can either use DStep or do the conversion manually. If DStep succeeds, you have something to work with quickly. With the manual approach you can also port stuff like preprocessor macros to their respective D equivalents.

Structurally, a two-level approach for bindings is recommended. On a first level try to clone the C API as close as possible. On the second level, you can optionally wrap convenience around, which exploits D-specific features.

A repository of bindings is Deimos. Please, submit bindings when you have created some.

C++ Interop

More limited than C interop, but possible to a certain extend.

Porting Code

Porting C/C++ code to D is relatively easy, since the languages are very similar.

See also

Converting C to D, C++ to D, C Preprocessor to D,