1/* -*-c-*- */ 2#include "ffitest.h" 3#include <complex.h> 4 5_Complex T_C_TYPE 6return_c(_Complex T_C_TYPE c1, _Complex T_C_TYPE c2, 7 unsigned int in3, _Complex T_C_TYPE c4) 8{ 9 volatile _Complex T_C_TYPE r = c1 + c2 + in3 + c4; 10 return r; 11} 12 13int main (void) 14{ 15 ffi_cif cif; 16 ffi_type *args[MAX_ARGS]; 17 void *values[MAX_ARGS]; 18 _Complex T_C_TYPE c1, c2, c4, rc, rc2; 19 unsigned int in3; 20 args[0] = &T_FFI_TYPE; 21 args[1] = &T_FFI_TYPE; 22 args[2] = &ffi_type_uint; 23 args[3] = &T_FFI_TYPE; 24 values[0] = &c1; 25 values[1] = &c2; 26 values[2] = &in3; 27 values[3] = &c4; 28 29 /* Initialize the cif */ 30 CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 4, 31 &T_FFI_TYPE, args) == FFI_OK); 32 c1 = 127.0 + 255.0 * I; 33 c2 = 128.0 + 256.0; 34 in3 = 255; 35 c4 = 512.7 + 1024.1 * I; 36 37 ffi_call(&cif, FFI_FN(return_c), &rc, values); 38 rc2 = return_c(c1, c2, in3, c4); 39 printf ("%f,%fi vs %f,%fi\n", 40 T_CONV creal (rc), T_CONV cimag (rc), 41 T_CONV creal (rc2), T_CONV cimag (rc2)); 42 CHECK(rc == rc2); 43 exit(0); 44} 45