1/* -*-c-*- */
2#include "ffitest.h"
3#include <complex.h>
4
5static _Complex T_C_TYPE return_c(_Complex T_C_TYPE c1, _Complex T_C_TYPE c2, unsigned int in3, _Complex T_C_TYPE c4)
6{
7  return c1 + c2 + in3 + c4;
8}
9int main (void)
10{
11  ffi_cif cif;
12  ffi_type *args[MAX_ARGS];
13  void *values[MAX_ARGS];
14  _Complex T_C_TYPE c1, c2, c4, rc, rc2;
15  unsigned int in3;
16  args[0] = &T_FFI_TYPE;
17  args[1] = &T_FFI_TYPE;
18  args[2] = &ffi_type_uint;
19  args[3] = &T_FFI_TYPE;
20  values[0] = &c1;
21  values[1] = &c2;
22  values[2] = &in3;
23  values[3] = &c4;
24
25  /* Initialize the cif */
26  CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 4,
27		     &T_FFI_TYPE, args) == FFI_OK);
28  c1 = 127.0 + 255.0 * I;
29  c2 = 128.0 + 256.0;
30  in3 = 255;
31  c4 = 512.7 + 1024.1 * I;
32
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 ==  c1 + c2 + in3 + c4);
39  exit(0);
40}
41