Seg fault when calling C code

Ali Çehreli via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri May 16 08:27:42 PDT 2014


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 but 
conceptually, the compiler does not pass .ptr directly; it passes the 
address of the entire array. Since the address of the entire static 
array is the same as the address of its first element it equals a.ptr 
and works perfectly in the C land.

Ali



More information about the Digitalmars-d-learn mailing list