Re: Seg fault when calling C code

2014-05-20 Thread Kagamin via Digitalmars-d-learn
On Friday, 16 May 2014 at 14:52:17 UTC, Marc Schütz wrote: But that's extern(C++), not extern(C)... That should be a different name mangling, so won't link. Winapi functions are declared as extern C for C++ compiler.

Re: Seg fault when calling C code

2014-05-16 Thread Kagamin via Digitalmars-d-learn
For example, windows headers do use C++ -references in function signatures and msdn provides code examples using that convention, the equivalent in D is ref.

Re: Seg fault when calling C code

2014-05-16 Thread via Digitalmars-d-learn
On Friday, 16 May 2014 at 11:42:35 UTC, Kagamin wrote: For example, windows headers do use C++ -references in function signatures and msdn provides code examples using that convention, the equivalent in D is ref. But that's extern(C++), not extern(C)...

Re: Seg fault when calling C code

2014-05-16 Thread Andrew Brown via Digitalmars-d-learn
On Friday, 16 May 2014 at 14:52:17 UTC, Marc Schütz wrote: On Friday, 16 May 2014 at 11:42:35 UTC, Kagamin wrote: For example, windows headers do use C++ -references in function signatures and msdn provides code examples using that convention, the equivalent in D is ref. But that's

Re: Seg fault when calling C code

2014-05-16 Thread Ali Çehreli via Digitalmars-d-learn
On 05/16/2014 08:15 AM, Andrew Brown wrote: I guess my confusion came about because in the page about interfacing with C, there's a static array example where parameters are given in terms D understands: extern (C) { void foo(ref int[3] a); // D prototype } I guess D has no problem

Re: Seg fault when calling C code

2014-05-16 Thread Andrew Brown via Digitalmars-d-learn
I guess my confusion came about because in the page about interfacing with C, there's a static array example where parameters are given in terms D understands: extern (C) { void foo(ref int[3] a); // D prototype } I guess D has no problem translating that into a simple pointer that C can

Re: Seg fault when calling C code

2014-05-16 Thread Ali Çehreli via Digitalmars-d-learn
On 05/16/2014 08:24 AM, Ali Çehreli wrote: On 05/16/2014 08:15 AM, Andrew Brown wrote: void foo(ref int[3] a); // D prototype Since we know that references are implemented as pointers, 'ref int[3] a' is passed as a.ptr. Sorry, that's confusing. Yes, it ends up being equal to a.ptr

Re: Seg fault when calling C code

2014-05-15 Thread Ali Çehreli via Digitalmars-d-learn
On 05/15/2014 01:55 PM, Andrew Brown wrote: extern(C) { void regress(int nInd, int nCov, ref double[] x, ref double[] y, ref double[] rOut); } I don't think that should even be allowed. C functions should not know or be compatible with 'ref' D parameters. Define the arguments as simple

Re: Seg fault when calling C code

2014-05-15 Thread Andrew Brown via Digitalmars-d-learn
That worked a treat! Thank you very much! On Thursday, 15 May 2014 at 21:11:54 UTC, Ali Çehreli wrote: On 05/15/2014 01:55 PM, Andrew Brown wrote: extern(C) { void regress(int nInd, int nCov, ref double[] x, ref double[] y, ref double[] rOut); } I don't think that should even be