Thread overview
D array to c
Jun 06, 2014
Harpo
Jun 06, 2014
Philpax
Jun 06, 2014
Harpo
Jun 06, 2014
Harpo
June 06, 2014
Hello I need to pass a array in D to c. I have edited the code to the important parts. Normally in C I would just do this:

void myFunction(int *array)
{
}

Then pass it a array of whatever size. However I actually need the array to be in a struct so...

typedef struct{int* array;} examplestruct;

void myFunction(examplestruct parameter){


}

On the D end what type structure do I need to use to pass a array of unknown size inside a struct to the c function? I have tried stuff like:

struct examplestruct {long* array;}
long numar[50];
examplestruct parameters;
parameters.array = numuar;

When I do that I get type conflictions.  Error: cannot implicitly convert expression (numar) of type long[50] to long*...
I am not sure what setup I need to have here. Anyone know whats up?

Thanks! -Harpo
June 06, 2014
On Friday, 6 June 2014 at 03:40:41 UTC, Harpo wrote:
> Hello I need to pass a array in D to c. I have edited the code to the important parts. Normally in C I would just do this:
>
> void myFunction(int *array)
> {
> }
>
> Then pass it a array of whatever size. However I actually need the array to be in a struct so...
>
> typedef struct{int* array;} examplestruct;
>
> void myFunction(examplestruct parameter){
>
>
> }
>
> On the D end what type structure do I need to use to pass a array of unknown size inside a struct to the c function? I have tried stuff like:
>
> struct examplestruct {long* array;}
> long numar[50];
> examplestruct parameters;
> parameters.array = numuar;
>
> When I do that I get type conflictions.  Error: cannot implicitly convert expression (numar) of type long[50] to long*...
> I am not sure what setup I need to have here. Anyone know whats up?
>
> Thanks! -Harpo

Use numar.ptr to get a long* pointer. Also, are you sure you want to use 64-bit integers on the D side?  Are you sure the C compiler is using 64-bit for its integers?
June 06, 2014
sorry thats:


struct examplestruct {int* array;}
int numar[50];
examplestruct parameters;
parameters.array = numuar;

When I do that I get type conflictions.  Error: cannot implicitly
convert expression (numar) of type int[50] to int*...
I am not sure what setup I need to have here. Anyone know whats
up?

(That int / long bit was just a typo when I was editing to just the relevent parts.)
June 06, 2014
Thanks that was perfect.
Also I am aware of the use of the 64bit numbers. Thank you for pointing it out though.