D array to c
Philpax via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Thu Jun 5 20:44:03 PDT 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?
More information about the Digitalmars-d-learn
mailing list