4 ms·
Author here, AMA. This is a link to my blog post about a project that allows one to directly #include C headers in D code, which can then be compiled and linked
by atilaneves 9y ago
Author here, AMA. This is a link to my blog post about a project that allows one to directly #include C headers in D code, which can then be compiled and linked. It's worked for non-trivial C libraries such as pthread, openssl and libcurl.
- flohofwoe 9y agoAwesome, this is exactly how I wish all 'better C' languages would allow C interop instead of going through separate binding-generator tools. The C (not C++) language itself is simple enough that at least a struct/function declarations parser shouldn't add too much code to any compiler (even if not using LLVM for this). The best solution would be to also allow directly referencing .c implementation files from D source, for separate compilation and linking with the D program. Nim does allow something like this: https://github.com/floooh/sokol-nim/blob/master/sokol/gfx.nim#L10 https://github.com/floooh/sokol-nim/blob/master/sokol/gfx.ni..., but I guess since Nim compiles to C this is much easier to achieve :)
- atilaneves 9y agoThe language that is commonly known as C is simple. Real C isn't because of the preprocessor. There's no way to do it properly unless one uses an actual C compiler. Viva libclang!