Interfacing D with C: Arrays and Functions (Arrays Part 2)

Seb seb at wilzba.ch
Tue Apr 28 16:12:32 UTC 2020


On Tuesday, 28 April 2020 at 14:45:37 UTC, Mike Parker wrote:
> I've finally gotten around to publishing the next article in my 
> D and C series on the D blog. This is the second post about 
> arrays, focusing on properly declaring in D functions from C 
> that accept array parameters.
>
> The blog:
> https://dlang.org/blog/2020/04/28/interfacing-d-with-c-arrays-and-functions-arrays-part-two/
>
> Reddit:
> https://www.reddit.com/r/programming/comments/g9o3wi/interfacing_d_with_c_arrays_and_functions_arrays/
>
> HN:
> https://news.ycombinator.com/item?id=23007409

Great article as always!
Maybe this article and conversation revives the interest in a 
very much related area: array mangling still doesn't work for 
extern(C++).
Example:

---
extern(C++) void foo(int[] arr);
void main()
{
    foo([1, 2]);
}
---

// Internal Compiler Error: type int[] cannot be mapped to C++

There have been multiple attempts to fix this, the latest one is 
https://github.com/dlang/dmd/pull/8120.
Now, that dmd comes with the (experimental) -H flag for C++ 
header generation, maybe there's more interest in making D 
arrays/strings work seamlessly between D and C++?


More information about the Digitalmars-d-announce mailing list