Why passing an array from C to System Verilog via DPI-C doesn't work?

Hi,

I am trying to understand how to pass an fix-size array from C side to SV side, why it only works on VCS, not NC?

Is a tool issue or bug in the code?

SV code:


module tb;
  int buffer[2];

  import "DPI-C" function void slave_write(input int addr, input int data, int buffer[2]);
  export "DPI-C" function write;

  function void write_test(int addr, int data, output int buffer[2]);
    //Call C function
    $display("before-buffer[2]:%p",buffer);
    slave_write(addr, data, buffer);
    $display("after-buffer[2]:%p",buffer);
  endfunction

  function void write(input int buff[2]);
    //export the array from C to SV
    buffer = buff;
    $display("output buffer[2]:%p",buffer);
  endfunction
  
  initial begin
    write_test(8'h30, 8'hff, buffer);
    $display("%p\n",buffer);
  end
endmodule

C code:


extern void write(int *buffer); // Imported from SystemVerilog

void slave_write(int I1, int I2, int *buff) {

  buff[0] = I1;
  buff[1] = I2;
  write(buff);
  printf("after write call\n");
}

In reply to mlsxdx:

Your DPI statements do not match the corresponding C prototypes.

 import "DPI-C" context function void slave_write(input int addr, input int data, output int buffer[2]);
void write(const int* buff);

Questa has option to generate a header file based on your DPI statements that you can include in your C code to make sure the prototypes match.

In reply to dave_59:

Thanks, Dave.
It gets resolve.

import “DPI-C” context function void slave_write(input int addr, input int data, output int buffer[2]);

output is needed here in the C prototypes.