On Sun, 10 Aug 2014 14:26:27 +0000
seany via Digitalmars-d-learn <digitalmars-d-learn@puremagic.com> wrote:

> I am having difficulty in imagining how to send D arrays to a C 
> function.
do something like this:

=== C SIDE ===
void c_array_processing (int *items, size_t item_count) {
  // use items pointer as normal C-like array pointer
  ...
}

=== D SIDE ===
extern(C) void c_array_processing (int* items, size_t item_count);

int[] arr;
...
arr ~= 42;
...
c_array_processing(arr.ptr, arr.length);


> PS: is there a built in size operator for arrays in D?
if you want to get size of all array items, do this:

size_t dataSize = arr[0].sizeof*arr[0].length;

if you want to get the size of the internal array structure... just
don't do that. it's better to not use internal compiler and runtime
structures.

Attachment: signature.asc
Description: PGP signature

Reply via email to