On Monday, 3 October 2016 at 12:08:54 UTC, Chalix wrote:
Hi All!

The documentation of D (https://dlang.org/overview.html#compatibility) says:

"Direct Access to C API's

Not only does D have data types that correspond to C types, it provides direct access to C functions. There is no need to write wrapper functions, parameter swizzlers, nor code to copy aggregate members one by one."


So, if there is no need for wrapper functions, why are there a lot of them? For example, GTK+ is a C library, with C-include files. Now there exists the GtkD (http://gtkd.org/) library, which describes itself as a wrapper of GTK+. GtkD contains the .d files (which I need for import, of course) and a seperate library (libgtkd-3.so). If D has direct Access to C API's, why do we need this the gtkd-3 lib, and not just use the gtk-3 lib?

Furthermore, if there is an not very popular C library, where no wrapper function exists, would it possible to include it into a D project? Probably I have to transform all the .h to .d files, so i can "import" them instead of "include" them. But then, could I link against the C-library?


I did not understand the concept of interaction between C and D, and I am a bit confused about wrapper functions and bindings for D now... Would be great if someone could make it a bit more clear to me :)

D provides ways to do things that C or C++ don't provide (otherwise we wouldn't be using it). C/C++ functions and structures are designed to fit well in C/C++, not in D. To make them easy to use and avoid code of mixed style we build up a facade : the wrapper. That's all.

Reply via email to