You can never take a C or C ++ file and compile it as D code, and you cannot just #include C headers in D. D is not backward compatible with either C or C ++. Rather, you can declare extern(C) functions in your D code and call these C functions as if they were D functions (naturally, you need to link to the C library in which they are defined). Cm
for details on calling C code from D.
druntime (which contains the kernel modules. *) has declarations for quite a few standard C and OS functions (in the core.stdc. * and core.sys. * modules), but you will have to search the files in droutime yourself to find out what they are, because they have not been properly documented at this time. For any other C functions that you want to call, you can easily create declarations for them yourself, as described in the links above.
Now C and D are very similar to syntax, so some sections of C code will be compiled simply as D-code, but there will be no programs in general. The general rule is that C / C ++ code will either be compiled as a valid D code with the same semantics, or it will not compile as a D code. There are several cases where this is not the case (for example, static arrays are value types in D, unlike C / C ++), but this is almost the case. This makes it easy to port C / C ++ code to D, but it has never been assumed that D would be backward compatible with C code like C ++.
Jonathan m davis
source share