#include #include #include typedef struct testStruct { int32_t m1; int32_t m2; int32_t m3; } testStruct; char *testFunc(int64_t l1, int64_t l2, int64_t l3, int64_t l4, int64_t l5, int64_t l6, int64_t l7, int64_t l8, double d1, double d2, double d3, double d4, double d5, double d6, double d7, double d8, testStruct s1, float f1, char *p1) { printf("d8=%lf, s1.m1=%d, s1.m2=%d, s1.m3=%d, f1=%f, p1=%p\n", d8, s1.m1, s1.m2, s1.m3, f1, p1); return p1; } int main() { ffi_cif cif; ffi_type *args[19]; void *values[19]; ffi_arg rc; int64_t int64Args[] = { 101, 102, 103, 104, 105, 106, 107, 108 }; double doubleArgs[] = { -1.0, -2.0, -3.0, -4.0, -5.0, -6.0, -7.0, -8.0 }; testStruct structArg = { 201, 202, 203 }; float floatArg = 12.3f; char *str = "ABCDE"; char *ptrArg = str; ffi_type testStructType; ffi_type *testStructElements[4] = { &ffi_type_float, &ffi_type_float, &ffi_type_sint32, NULL }; testStructType.size = 0; testStructType.alignment = 0; testStructType.type = FFI_TYPE_STRUCT; testStructType.elements = testStructElements; /* Initialize the argument info vectors */ args[0] = &ffi_type_sint64; args[1] = &ffi_type_sint64; args[2] = &ffi_type_sint64; args[3] = &ffi_type_sint64; args[4] = &ffi_type_sint64; args[5] = &ffi_type_sint64; args[6] = &ffi_type_sint64; args[7] = &ffi_type_sint64; args[8] = &ffi_type_double; args[9] = &ffi_type_double; args[10] = &ffi_type_double; args[11] = &ffi_type_double; args[12] = &ffi_type_double; args[13] = &ffi_type_double; args[14] = &ffi_type_double; args[15] = &ffi_type_double; args[16] = &testStructType; args[17] = &ffi_type_float; args[18] = &ffi_type_pointer; values[0] = int64Args; values[1] = int64Args + 1; values[2] = int64Args + 2; values[3] = int64Args + 3; values[4] = int64Args + 4; values[5] = int64Args + 5; values[6] = int64Args + 6; values[7] = int64Args + 7; values[8] = doubleArgs; values[9] = doubleArgs + 1; values[10] = doubleArgs + 2; values[11] = doubleArgs + 3; values[12] = doubleArgs + 4; values[13] = doubleArgs + 5; values[14] = doubleArgs + 6; values[15] = doubleArgs + 7; values[16] = &structArg; values[17] = &floatArg; values[18] = &ptrArg; /* Call the function without ffi */ testFunc(int64Args[0], int64Args[1], int64Args[2], int64Args[3], int64Args[4], int64Args[5], int64Args[6], int64Args[7], doubleArgs[0], doubleArgs[1], doubleArgs[2], doubleArgs[3], doubleArgs[4], doubleArgs[5], doubleArgs[6], doubleArgs[7], structArg, floatArg, ptrArg); if (ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 19, &ffi_type_pointer, args) == FFI_OK) { ffi_call(&cif, testFunc, &rc, values); } return 0; }