return_complex2.inc 1004 B

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