1/* -*-c-*- */ 2#include "ffitest.h" 3#include <complex.h> 4 5static _Complex T_C_TYPE return_c(_Complex T_C_TYPE c) 6{ 7 printf ("%f,%fi\n", T_CONV creal (c), T_CONV cimag (c)); 8 return 2 * c; 9} 10int main (void) 11{ 12 ffi_cif cif; 13 ffi_type *args[MAX_ARGS]; 14 void *values[MAX_ARGS]; 15 _Complex T_C_TYPE c, rc, rc2; 16 T_C_TYPE cr, ci; 17 18 args[0] = &T_FFI_TYPE; 19 values[0] = &c; 20 21 /* Initialize the cif */ 22 CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 1, 23 &T_FFI_TYPE, args) == FFI_OK); 24 25 for (cr = -127.0; cr < 127; cr++) 26 { 27 ci = 1000.0 - cr; 28 c = cr + ci * I; 29 ffi_call(&cif, FFI_FN(return_c), &rc, values); 30 rc2 = return_c(c); 31 printf ("%f,%fi vs %f,%fi\n", 32 T_CONV creal (rc), T_CONV cimag (rc), 33 T_CONV creal (rc2), T_CONV cimag (rc2)); 34 CHECK(rc == 2 * c); 35 } 36 exit(0); 37} 38