Communication between D and C with dynamic arrays

seany via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Aug 10 07:26:27 PDT 2014


In D, arrays are dynamic. However, to the best of my knowledge, 
in C, they are static.

I am having difficulty in imagining how to send D arrays to a C 
function.

My first Idea was to make a pointer to the array. then find the 
size of the array, which itself is an array, therefore take the 
pointer to it, then get the dimension of the array, which is an 
integer, and send the trio of two pointers and the dimesion to 
the C code.

Now this arises two questions :

1. I assume that D allocates a particular space to the array, say 
N elements, and up to these N elements, you can increment the 
pointers, to jump to next array element.

What happens if the N element space is used up? Does the pointer 
incrementing method break down?

2. in D pointers are being converted to void * as I read in the 
reply to another post of mine. I dont remember in my knowledge of 
C, that they are accepted in C, are they? Do I have to meake a 
type retrospection every time I get send something to C?

Any help is appreciated.

PS: is there a built in size operator for arrays in D?


More information about the Digitalmars-d-learn mailing list