DPI question that SV export function return various amount of data to C function

In my scenario C function is caller and SV export function is callee. The SV function needs to return various amount of data back to C function, based on the size input parameter.

From the LRM H.8.8, inout and output arguments, with the exception of open arrays, are always passed by reference, the following pseudo SV function is defined:

function void execute(int size, output data[128]);
    if (size > 128) `uvm_fatal(...)
    for(int i = 0; i < size; i++) data[i] = $urandom;
endfunction

In C, can we write the following code by assuming above SV function write 32 integers directly into C’s data array.

int data[32];
execute(32, data);

In reply to robert.liu:
You forgot to declare data as an array of int. But the bigger problem is you can’t have the exported function array argument have 128 ints, but on the C side, you only allocated 32. The SystemVerilog side will copy out 96 extra elements corrupting your stack.

You need to make the arrays on both language sides the same max size

module top;
  
  export "DPI-C" function  execute;
  import "DPI-C" context function  void Crun();
  
  function void execute(int size, output int data[128]);
    if (size > 128) $fatal(0,"cant handle size over 128");
      for(int i = 0; i < size; i++) begin
        data[i] = $urandom_range(10);
        $display("SV %0x", data[i]);
      end
    endfunction
  
    initial Crun();
endmodule
#include "Crun.h"
#include "stdio.h"
#include "vpi_user.h"
void Crun () {
  int A[128];
  execute(5,A);
  for(int i=0;i<5;i++)
    vpi_printf("C %0x\n", A[i]);
}