DPI allows to pass the structs and Unions . This can be done by passing pointers or by packing.
In the following example, a "struct" is passed from SystemVerilog to C and also from C to Systemverilog using import and export functions. While passing the "struct" data type, the data is packed in to array and passed from SV to C and then the array is decoded back to Struct in C. The same when the Struct is passed from C to SystemVerilog.
C : 0 : [303379748,-1064739199]
C : 1 : [-2071669239,-1309649309]
C : 2 : [112818957,1189058957]
C : 3 : [-1295874971,-1992863214]
C : 4 : [15983361,114806029]
Passing Union Example
CODE:SV_file module m;
typedefbit [2:0] A;
typedefunionpacked { A a; S s; } U;
U u;
A a;
// Import function takes three arguments import "DPI-C" functionvoid foo8(input A fa, input U fu);
initialbegin
a = 3'b100;
u.a = 3'b100;
foo8(a, u); end
endmodule
CODE:C_file
#include "svdpi.h"
void foo8( const svBitVecVal* fa, const svBitVecVal* fu)
{
printf("fa is %d, fu is %d\n", *fa, *fu);
}