Jump to page: 1 26  
Page
Thread overview
#include C headers in D code
Apr 09, 2018
Atila Neves
Apr 09, 2018
jmh530
Apr 09, 2018
Cym13
Apr 09, 2018
SrMordred
Apr 09, 2018
Colin
Apr 09, 2018
kinke
Apr 09, 2018
bachmeier
Apr 09, 2018
Atila Neves
Apr 09, 2018
Seb
Apr 10, 2018
Atila Neves
Apr 10, 2018
Joakim
Apr 11, 2018
Kagamin
Apr 11, 2018
Jonathan M Davis
Apr 11, 2018
bachmeier
[OT] gdc status
Apr 11, 2018
drug
Apr 11, 2018
Uknown
Apr 11, 2018
drug
Apr 11, 2018
Daniel Kozak
Apr 13, 2018
Johannes Pfau
Apr 11, 2018
Kagamin
Apr 11, 2018
Kagamin
Apr 10, 2018
Stefan
Apr 10, 2018
Walter Bright
Apr 10, 2018
Atila Neves
Apr 10, 2018
Atila Neves
Apr 10, 2018
Atila Neves
Apr 10, 2018
Atila Neves
Apr 10, 2018
Seb
Apr 10, 2018
David Nadlinger
Apr 10, 2018
Atila Neves
Apr 11, 2018
Jacob Carlborg
Apr 11, 2018
Atila Neves
Apr 11, 2018
rikki cattermole
Apr 11, 2018
Atila Neves
Apr 11, 2018
Jacob Carlborg
Apr 11, 2018
Atila Neves
Apr 11, 2018
Walter Bright
Apr 12, 2018
John Colvin
Apr 12, 2018
Nemanja Boric
Apr 11, 2018
Jacob Carlborg
Apr 13, 2018
Atila Neves
Apr 11, 2018
Jacob Carlborg
Apr 13, 2018
Atila Neves
Apr 16, 2018
Atila Neves
Apr 16, 2018
Jacob Carlborg
Apr 16, 2018
Atila Neves
Apr 11, 2018
rumbu
Apr 13, 2018
Atila Neves
Apr 13, 2018
Jacob Carlborg
Apr 16, 2018
Chris
April 09, 2018
Here's my blog post about my project that allows directly #including C headers in D*

https://atilanevesoncode.wordpress.com/2018/04/09/include-c-headers-in-d-code/

The summary is that, modulo bugs, things like this work:

    #include <stdio.h>
    void main() { printf("Hello world\n".ptr); }

So far it's successfully compiled whilst #including pthread, libcurl, openssl and others. The blog and the github README have more information, and feel free to reply to this with questions.

dub: http://code.dlang.org/packages/dpp
reddit: https://www.reddit.com/r/programming/comments/8axj53/include_c_headers_in_d_code/
hacker news: It's in there somewhere, search around.

Atila

* Technically, "D + #include directives + C macros"
April 09, 2018
On Monday, 9 April 2018 at 11:03:48 UTC, Atila Neves wrote:
> Here's my blog post about my project that allows directly #including C headers in D*
>
> [snip]

Fantastic.
April 09, 2018
On Monday, 9 April 2018 at 11:48:51 UTC, jmh530 wrote:
> On Monday, 9 April 2018 at 11:03:48 UTC, Atila Neves wrote:
>> Here's my blog post about my project that allows directly #including C headers in D*
>>
>> [snip]
>
> Fantastic.

This is so cool, I think it should be featured on the D blog as well (maybe when you get to your goal of having C++ features working consistently).

More exposure is better exposure.
April 09, 2018
On Monday, 9 April 2018 at 11:03:48 UTC, Atila Neves wrote:
> Here's my blog post about my project that allows directly #including C headers in D*
>
> https://atilanevesoncode.wordpress.com/2018/04/09/include-c-headers-in-d-code/
>
> The summary is that, modulo bugs, things like this work:
>
>     #include <stdio.h>
>     void main() { printf("Hello world\n".ptr); }
>
> So far it's successfully compiled whilst #including pthread, libcurl, openssl and others. The blog and the github README have more information, and feel free to reply to this with questions.
>
> dub: http://code.dlang.org/packages/dpp
> reddit: https://www.reddit.com/r/programming/comments/8axj53/include_c_headers_in_d_code/
> hacker news: It's in there somewhere, search around.
>
> Atila
>
> * Technically, "D + #include directives + C macros"

This is awesome!
i´ll try soon as possible :)

April 09, 2018
On Monday, 9 April 2018 at 11:03:48 UTC, Atila Neves wrote:
> Here's my blog post about my project that allows directly #including C headers in D*
>
> https://atilanevesoncode.wordpress.com/2018/04/09/include-c-headers-in-d-code/
>
> The summary is that, modulo bugs, things like this work:
>
>     #include <stdio.h>
>     void main() { printf("Hello world\n".ptr); }
>
> So far it's successfully compiled whilst #including pthread, libcurl, openssl and others. The blog and the github README have more information, and feel free to reply to this with questions.
>
> dub: http://code.dlang.org/packages/dpp
> reddit: https://www.reddit.com/r/programming/comments/8axj53/include_c_headers_in_d_code/
> hacker news: It's in there somewhere, search around.
>
> Atila
>
> * Technically, "D + #include directives + C macros"

This is very cool.

Gonna try it against gl.h tonight!
April 09, 2018
On Monday, 9 April 2018 at 11:03:48 UTC, Atila Neves wrote:
> Here's my blog post about my project that allows directly #including C headers in D*
>
> https://atilanevesoncode.wordpress.com/2018/04/09/include-c-headers-in-d-code/

Certainly interesting. Is there a good reason why you didn't look into Calypso though? It's restricted to LDC, okay, but its approach of fusioning C++ and D parts at the AST and LLVM-IR level seems far more promising to me - no need to translate the C(++) parts to D and let the underlying D compiler parse & analyze all that generated code again. And Calypso's C++ support is apparently mature enough to interface with Qt5 (!)...
April 09, 2018
On Monday, 9 April 2018 at 18:15:33 UTC, kinke wrote:
> On Monday, 9 April 2018 at 11:03:48 UTC, Atila Neves wrote:
>> Here's my blog post about my project that allows directly #including C headers in D*
>>
>> https://atilanevesoncode.wordpress.com/2018/04/09/include-c-headers-in-d-code/
>
> Certainly interesting. Is there a good reason why you didn't look into Calypso though? It's restricted to LDC, okay, but its approach of fusioning C++ and D parts at the AST and LLVM-IR level seems far more promising to me - no need to translate the C(++) parts to D and let the underlying D compiler parse & analyze all that generated code again. And Calypso's C++ support is apparently mature enough to interface with Qt5 (!)...

Aren't there limitations on what Calypso can do? I thought I read that it can't be made to work with all C code, but maybe I'm wrong... Of course, only working with LDC is itself a big restriction.
April 09, 2018
On Monday, 9 April 2018 at 18:15:33 UTC, kinke wrote:
> On Monday, 9 April 2018 at 11:03:48 UTC, Atila Neves wrote:
>> Here's my blog post about my project that allows directly #including C headers in D*
>>
>> https://atilanevesoncode.wordpress.com/2018/04/09/include-c-headers-in-d-code/
>
> Certainly interesting. Is there a good reason why you didn't look into Calypso though? It's restricted to LDC, okay, but its approach of fusioning C++ and D parts at the AST and LLVM-IR level seems far more promising to me - no need to translate the C(++) parts to D and let the underlying D compiler parse & analyze all that generated code again. And Calypso's C++ support is apparently mature enough to interface with Qt5 (!)...

This whole idea came about because a couple of years ago I was in a team that was responsible for legacy code written in C which had no tests. To write tests, we needed both to write the tests themselves and some fakes/mocks/doubles for the code that we depended on - essentially a whole operating system. I wasn't going to write that in C, since life is too short for that.

I wanted to write it in D, and even tried running dstep on one of the dependency headers we had - to no avail. Manual conversion was out of the question - too many headers, all them as coupled together as possible. So I sighed and started writing some C++14. I hated to admit it, but that mess of headers was only really usable from C or C++ (Objective C wasn't in the running). I still feel bad I picked C++ over D, but it was the right choice.

Why not Calypso? It's a hard enough task to convince a team of C programmers who don't know C++ that C++ was a better choice than C. It's a herculean task to convince them of D, a language they know even less and that they've never heard about (the first question is always "but which companies are using D?").

If you add to all that "No, really, it's ok, there's this project that forked one of the compilers. No, it's not the reference compiler. There's just this bit of non-standard syntax to learn that's neither C nor D", then the chances of convincing any "normal" engineer are 0.

C++ got popular because it lowered the barrier of adoption to 0. I want that for D.  Because of psychological reasons, I don't think Calypso is the way to do it, however much it's succeeded technically. And the whole point of dpp is convince the average coder and their managers.

April 09, 2018
On Monday, 9 April 2018 at 19:36:23 UTC, Atila Neves wrote:
> On Monday, 9 April 2018 at 18:15:33 UTC, kinke wrote:
>> [...]
>
> This whole idea came about because a couple of years ago I was in a team that was responsible for legacy code written in C which had no tests. To write tests, we needed both to write the tests themselves and some fakes/mocks/doubles for the code that we depended on - essentially a whole operating system. I wasn't going to write that in C, since life is too short for that.
>
> [...]

Speaking of dstep - it has greatly improved over the last years.
I'm interested what stop you from using it or improving it (instead of rolling your own tool)?
April 10, 2018
On Monday, 9 April 2018 at 11:03:48 UTC, Atila Neves wrote:
> Here's my blog post about my project that allows directly #including C headers in D*

neat!
« First   ‹ Prev
1 2 3 4 5 6