Re: how to pass a ubyte[] to c interface?

2015-03-13 Thread Rikki Cattermole via Digitalmars-d-learn
On 13/03/2015 7:47 p.m., zhmt wrote: On Friday, 13 March 2015 at 06:39:31 UTC, Rikki Cattermole wrote: On 13/03/2015 7:35 p.m., zhmt wrote: ubyte[] arr ; I pass the arr.ptr to c program, it fails silently. Is there any way to cast a ubyte[] to a clang pointer? Theoretically this should

Re: how to pass a ubyte[] to c interface?

2015-03-13 Thread zhmt via Digitalmars-d-learn
On Friday, 13 March 2015 at 06:39:31 UTC, Rikki Cattermole wrote: On 13/03/2015 7:35 p.m., zhmt wrote: ubyte[] arr ; I pass the arr.ptr to c program, it fails silently. Is there any way to cast a ubyte[] to a clang pointer? Theoretically this should work. D: void func(ubyte[] value) {

how to pass a ubyte[] to c interface?

2015-03-13 Thread zhmt via Digitalmars-d-learn
ubyte[] arr ; I pass the arr.ptr to c program, it fails silently. Is there any way to cast a ubyte[] to a clang pointer?

Re: how to pass a ubyte[] to c interface?

2015-03-13 Thread Rikki Cattermole via Digitalmars-d-learn
On 13/03/2015 7:35 p.m., zhmt wrote: ubyte[] arr ; I pass the arr.ptr to c program, it fails silently. Is there any way to cast a ubyte[] to a clang pointer? Theoretically this should work. D: void func(ubyte[] value) { func(value.length, value.ptr); } extern(C) void func(size_t

Re: how to pass a ubyte[] to c interface?

2015-03-13 Thread zhmt via Digitalmars-d-learn
I have some source code of vibe.d, it does this in the same way, and it works . void read(ubyte[] dst) { checkConnected(false); acquireReader(); scope(exit) releaseReader(); while (dst.length 0) {

Re: how to pass a ubyte[] to c interface?

2015-03-13 Thread Ali Çehreli via Digitalmars-d-learn
On 03/12/2015 11:35 PM, zhmt wrote: ubyte[] arr ; I pass the arr.ptr to c program Unless there is sentinel value at the end of the array, you must also pass the number of elements (as Rikki Cattermole has shown). However, if the C function holds on to that pointer for later use, you must

Re: how to pass a ubyte[] to c interface?

2015-03-13 Thread zhmt via Digitalmars-d-learn
On Friday, 13 March 2015 at 06:56:33 UTC, Ali Çehreli wrote: On 03/12/2015 11:35 PM, zhmt wrote: ubyte[] arr ; I pass the arr.ptr to c program Unless there is sentinel value at the end of the array, you must also pass the number of elements (as Rikki Cattermole has shown). However, if