Report a bug
If you spot a problem with this page, click here to create a Bugzilla issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page. Requires a signed-in GitHub account. This works well for small changes. If you'd like to make larger changes you may want to consider using a local clone.

C API headers

Version 1
Created 2011-10-18
StatusApproved
Last modified 2011-10-18
Author Martin Nowak

Abstract

Create a place to gather D import files for publicly available C libraries.

Rationale

D is binary compatible with C ABI code. This allows to reuse the huge amount of high quality public C libraries. Providing a central place to publish D import files can leverage the tedious work of translating.

Description

A repository was created under 1. It was proposed to use the following directory structure.

   deimos            |--- library name            |--- C               |--- foo.h                   |--- bar                       |--- baz.h            |--- D               |--- foo.d                   |--- bar                       |--- baz.d

Each ‘#include <path/to/header.h>’ should have a corresponding ‘import path.to.header;’

Possibly all files could be rooted under a package ‘cabi’, i.e. ‘import cabi.path.to.header;’.

The D import files should try to do as least modifications as possible to simplify updates of the C headers. This includes leaving comments intact.

Translated header should not require linkage of any D binary. Necessary D functions can be written as nullary templates.

   #define GET(x) x.value => int GET()(X x) { return x.value; }

Version tags should match the ones being used by the C headers.

The copyright for the D import files should match the one being used by the C header as they are derived work.

If the C header file has a name that is a D keyword, an underscore will be appended to the D module name.

If a C type name matches a C function name (stat), the type name will have a “_t” appended.

Open Questions

Starting with the phobos dev team.

Recommendations

Each library should contain a README in the root folder. The README file should contain exact source and version of the C library. Furthermore it should contain specific notes about the usage of the D import file.

Every library should contain a simple D example under CAPI/library/examples. This could be used for basic self testing.

This document has been placed in the Public Domain.