Ease of calling C code from D
Atila Neves
atila.neves at gmail.com
Tue Jan 28 12:09:59 PST 2014
One of D's marketed advantages it its compatibility with C. The C
standard library is even included! However, after having played
around with this quite a bit last week trying to call legacy C
code from D, the one thing that put me off and made me think that
C++ is better for this for my team is the C preprocessor.
Unfortunately a lot of C code has macros that call macros that
call other macros, and the only way to properly get around it is
to hand-translate them one by one.
There is htod but it's Windows only. I tried running it with
Wine, it didn't work right off the bat and if I had to go check
out why it didn't work I wasn't going to convince anyone at work
so I didn't bother. Also, from what I read here on the site I'm
sure it'd choke on the macros as well.
I know that having a fully-featured C preprocessor in a D
compiler is a bad idea for several reasons, but in C++ it's
#include "cheader.h" and, assuming one sets all the revelant -I
flags to the compiler, that's that. That really is a massively
important feature (with its downsides, I know).
For popular C libraries there's Deimos (and even then _somebody_
has to go to the work and make sure it compiles), but for legacy
code...
I guess my point is I'm glad I can call C code from D if I really
have to, but that I'd also think about it twice given the
interface issues. Another problem I had was the silly C code
taking char* instead of const char*. Passing in D strings was
"fun".
Atila
More information about the Digitalmars-d
mailing list