return_complex1.inc 970 B

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