www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.announce - Interfacing D with C: Arrays and Functions (Arrays Part 2)

reply Mike Parker <aldacron gmail.com> writes:
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
Apr 28
next sibling parent reply David Gileadi <gileadisNOSPM gmail.com> writes:
On 4/28/20 7:45 AM, 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-functi
ns-arrays-part-two/ 
.. Another great article! Nit: in the following paragraph, did you really mean to say *are*?
 But again, even D’s safety features are 100% foolproof when calling C
functions from D.
Apr 28
parent Mike Parker <aldacron gmail.com> writes:
On Tuesday, 28 April 2020 at 15:26:49 UTC, David Gileadi wrote:

 Another great article!

 Nit: in the following paragraph, did you really mean to say 
 *are*?

 But again, even D’s safety features are 100% foolproof when 
 calling C functions from D.
Thanks and thanks!
Apr 28
prev sibling next sibling parent reply Seb <seb wilzba.ch> writes:
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++?
Apr 28
parent Walter Bright <newshound2 digitalmars.com> writes:
On 4/28/2020 9:12 AM, Seb wrote:
 // 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++?
They're never going to work seamlessly between D and C++ because C++ does not have a standard compatible type for it. We discussed this at length at DConf 2019.
Apr 29
prev sibling parent Steven Schveighoffer <schveiguy gmail.com> writes:
On 4/28/20 10:45 AM, 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-functi
ns-arrays-part-two/ 
 
 
 Reddit:
 https://www.reddit.com/r/programming/comments/g9o3wi/interfacing_d_with_c_arrays_a
d_functions_arrays/ 
 
 
 HN:
 https://news.ycombinator.com/item?id=23007409
Nice! I was ready to respond with what turns out to be the punchline here -- using ref ;) That little bit of sorcery is an excellent trick that can make a world of difference when it comes to compiler-enforced correctness. -Steve
Apr 28