Hi,
I have a struct in C as follows. I am trying to pass this struct from C to SV and printing the values of each element in the struct. I am getting the correct value of “n” in both C and SV. But the 2D array values of “x” in C and SV are not matching. Please find the code snippet. If I try to pass the 2D array variable(“state.x”) alone from C to SV, it is working fine. But when passing the entire struct, it is not. Please let me know if it possible to pass a struct entirely from C to SV.
C:
==
struct state {
long n;
unsigned long **x;
};
extern void sv_getstate(struct state *q);
int main() {
struct state *q;
:
:
sv_getstate(q);
}
SV:
===
`define CNT 2
typedef struct {
longint n;
longint unsigned x [2*`CNT+1] [`CNT];
} state;
export "DPI-C" function sv_getstate;
import "DPI-C" context function int main(int argc, string argv[2:0]);
function void sv_getstate(input state y);
$display("y.n is : %0d",y.n);
for(int i=0;i<=2*y.n;i++) begin
for(int j=0;j<y.n;j++) begin
$display("y.x[%0d][%0d] : %0d",i,j,y.x[i][j]);
end
end
endfunction
initial begin
:
:
main(....)
end