Porting From C
This page needs contributors!
see NotesForProgrammersUsedTo/PlainC differences between C and D
Do you really need a full port?
The first thing to know is that D can call compiled C functions directly. So a full source port of the C code may not be necessary, and in fact it's rare to see C software fully ported directly to D. Instead people usually just do a header-only port, which is much less work. The most common exceptions are cases where the source code is relatively brief (like getopt, for instance).There is a downside to header-only ports: the D interface to the C library will naturally be limited to just the types that C understands. For instance, you won't be able to call the C functions directly with D 'char[]' or 'string' types, because C requires 'char*' to be null-terminated, and D strings aren't always so. Thus another option worth considering is making a headers + wrappers port, that is, first port the C headers as-is, then create another layer on top of that that handles simple translations between D types and C types, like calling std.string.toStringz to convert a D string to a 'char*'.
Tools
The main tools available to assist in porting C header files to D arehtod - Walter Bright's tool which can handle some C code.
BCD - (Old) Gregor Richard's translation tool based on gcc-xml.
DStep - Jacob Carlborg's Clang-based tool which can also translate from Objective-C?.
Return to the PortingOverview page.