Segmenting fault error

Hi,

I got segmenting fault error with below DPI codes.
Please let me know how to fix it.


// SV code
export "DPI-C" task randomize32;
class rand_define;
  rand bit [31:0] out;
  constraint const_out{out[31:0] >= 0; out[31:0] <= 32'hffff_ffff;};
endclass

task randomize32(output int out);
  bit [31:0] out;
  rand_define exec;

  begin
     exec = new();
     exec.randomize();
     out = exec.out;
     $display("random_data = %h", out); // display OK
  end
endtask

// C++ code
extern "C" void randomize32(int out);

void Test(void)
{
  int out;
  out = 0;
  randomize32(out); // display OK

  printf_sub("test bla bla"); // Looks Segmenting fault happend here
  .....
  .....
}

In reply to uvmbee:

Most tools provide the capability to generate C header files for DPI code. This can ensure that you have the correct function prototypes for your DPI code.

In this case, for a task with an output variable of type int, the correct function prototype is:

extern "C" int randomize32(int* out);

Hopefully this will help you determine what is incorrect in your C++ code.