Re: D array to void* and back

2015-08-03 Thread Steven Schveighoffer via Digitalmars-d-learn
On 8/3/15 5:23 PM, ref2401 wrote: Hello everyone, I pass a D array as void* into a function. When I'm trying to cast a void* parameter to a D array I get 'Access Violation' error. However if I define ArrayLike struct which looks like D array then casting will succeed. What should I do? Should I

Re: D array to void* and back

2015-08-03 Thread Ali Çehreli via Digitalmars-d-learn
On 08/03/2015 02:33 PM, ref2401 wrote: On Monday, 3 August 2015 at 21:28:29 UTC, Ali Çehreli wrote: But you still need to communicate how many elements there are in the array. (I used literal 3). Yes I do. I hope there is a neat way to pass array's length too. Not possible in C. :( Common

Re: D array to void* and back

2015-08-03 Thread ref2401 via Digitalmars-d-learn
On Monday, 3 August 2015 at 21:28:29 UTC, Ali Çehreli wrote: But you still need to communicate how many elements there are in the array. (I used literal 3). Yes I do. I hope there is a neat way to pass array's length too.

D array to void* and back

2015-08-03 Thread ref2401 via Digitalmars-d-learn
Hello everyone, I pass a D array as void* into a function. When I'm trying to cast a void* parameter to a D array I get 'Access Violation' error. However if I define ArrayLike struct which looks like D array then casting will succeed. What should I do? Should I stick to ArrayLike wrapper and j

Re: D array to void* and back

2015-08-03 Thread Ali Çehreli via Digitalmars-d-learn
On 08/03/2015 02:23 PM, ref2401 wrote: > void funcLibC_Array(void* data) { > int[] arr = *cast(int[]*)data; You are still in D, so int[] has a different meaning from a C array. (D's arrays are array-like. ;) ) Since arr.ptr is the pointer to the first element, and since that is exactly