Hello,
I am trying to pass a string from C to a SV task, but in SV domain, the string looks corrupted instead of alphabetical characters of the original value (“/home/dir/”) in C. Any idea why? Thanks.
extern "C" void Print_String_SV (string dir);
void Init_CSP_Mem_BD () { // this is a C function
char *a_string = "/home/dir/";
Print_String_SV (a_string);
}
module module_t ();
export "DPI-C" task Print_String_SV;
task Print_String_SV (string str);
$display ("This is string value %s", str);
endtask
endmodule
In reply to dnguyen82us:
I am surprised this even compiled for you. A C++
string is a class, not a pointer to a
char
extern "C"
int Init_CSP_Mem_BD();
extern "C" int
Print_String_SV( const char * str);
int Init_CSP_Mem_BD () {
char a_string[] = "/home/dir/";
Print_String_SV (a_string);
return 0;
}
module module_t ();
import "DPI-C" context task Init_CSP_Mem_BD();
export "DPI-C" task Print_String_SV;
task Print_String_SV (string str);
$display ("This is string value %s", str);
endtask : Print_String_SV
initial Init_CSP_Mem_BD;
endmodule : module_t
Note that some tools can automatically generate the correct C prototypes as a header file that you can include. That way you are guaranteed to get a compiler error if you argument types do not match.