Hello,
I’m using DPI to interchange data between SV and C. If I define an array (2dim) in SV as…
module tb();
import "DPI-C" function int myFunction (int i_data[][]);
int i_data[][];
i_data= new[3];
i_data[0] = new[1];
i_data[1] = new[10];
i_data[2] = new[4];
...
i = myFunction(i_data);
...
endmodule;
How to read this array with different length in the second dimension?
I wrote the myFunction like:
#include "svdpi.h"
#include <stdio.h>
#include <stdlib.h>
int myFunction(const svOpenArrayHandle i_data)
{
int lengths[3] = {1, 10, 4};
int tmp = 0;
for (int i = 0; i < svSize(i_data,1); i++) {
printf("Inputs: %d ", i);
for (int j = 0; j < i_paral[i]; j++) {
tmp = *((int*) svGetArrElemPtr2(i_data, i, j));
printf("data: %d", tmp);
}
}
return 1;
}
But the output messages is wrong.
When I print the output message with svLow(i_data, 1), svHigh(i_data,1) is OK. When I try to print svLow(i_data, 2), svHigh(i_data,2) both functions return “-1”.
Is possible to use DPI with array two-dimensional with different lengths (dynamical creation)?