extern(C) with function returning user type

Kyoji Klyden via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Jul 30 20:30:18 PDT 2015


On Thursday, 30 July 2015 at 11:32:10 UTC, bachmeier wrote:
> On Thursday, 30 July 2015 at 01:14:06 UTC, Mike Parker wrote:
>> On Wednesday, 29 July 2015 at 18:42:45 UTC, Kyoji Klyden wrote:
>>> Thanks for the replies,
>>>
>>> This issue really highlights one of D's weak points I think.
>>>
>>> I've atleast got a round about solution almost working. :P
>>
>> Really? I see it as one of D's strengths. It's much easier to 
>> connect D with C than it is to connect other languages with C. 
>> Essentially, you're just rewriting the C header in D and 
>> that's it. It's as simple as it can get without the compiler 
>> being able to directly parse C headers. In that case, the 
>> compiler would either be needlessly complex or have a 
>> dependency on something like libclang. This is much more 
>> appropriate for a tool, not the compiler. Besides, it's quite 
>> easy to do it by hand.
>
> I agree. The last thing we want is C header files being valid D 
> code. It would make C programmers happy, but understanding 
> those ugly files would then become a requirement for anyone 
> coming from a different background, and that would not be good. 
> Trivial interoperability (even if it's inconvenient) that 
> leaves the two languages separate is far better.

Being that my skills in C and D are pretty much tied, I regularly 
find myself writing a D program, only to find that I can't 
actually link with whatever C based library I'm using at the 
moment, so it actually ends up being faster and far more 
efficient to just rewrite all my D source in C (and a tiny bit of 
C++ if I really have to).

 From D, using C functions is easy, but I always run into trouble 
when it comes to any of the user types. So I guess I could bind 
it, but again that can take too much time when you got 20 massive 
headers all referencing each other.

So idk, it feels silly and counterproductive to have D not able 
to natively use C libraries. Are we just gonna have to write D 
bindings to every notable library out there? Also I don't see how 
it'd be problematic, if you don't want a C preprocessor kicking 
in, then just don't import any C source, and then the compiler 
will just skip that step.  :P


On Thursday, 30 July 2015 at 18:26:15 UTC, Jacob Carlborg wrote:
> On 2015-07-29 20:42, Kyoji Klyden wrote:
>> Thanks for the replies,
>>
>> This issue really highlights one of D's weak points I think.
>>
>> I've atleast got a round about solution almost working. :P
>
> You might want to check out Calypso [1] as well.
>
> [1] 
> http://forum.dlang.org/thread/nsjafpymezlqdknmnkhi@forum.dlang.org#post-nsjafpymezlqdknmnkhi:40forum.dlang.org

That actually seems really interesting, I'll check it out later. 
Thanks!


More information about the Digitalmars-d-learn mailing list