• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/* -*-c-*- */
2#include "ffitest.h"
3#include <complex.h>
4
5static _Complex T_C_TYPE return_c(_Complex T_C_TYPE c1, float fl2, unsigned int in3, _Complex T_C_TYPE c4)
6{
7  return c1 + fl2 + 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, c4, rc, rc2;
15  float fl2;
16  unsigned int in3;
17  args[0] = &T_FFI_TYPE;
18  args[1] = &ffi_type_float;
19  args[2] = &ffi_type_uint;
20  args[3] = &T_FFI_TYPE;
21  values[0] = &c1;
22  values[1] = &fl2;
23  values[2] = &in3;
24  values[3] = &c4;
25
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  fl2 = 128.0;
31  in3 = 255;
32  c4 = 512.7 + 1024.1 * I;
33
34  ffi_call(&cif, FFI_FN(return_c), &rc, values);
35  rc2 = return_c(c1, fl2, in3, c4);
36  printf ("%f,%fi vs %f,%fi\n",
37	  T_CONV creal (rc), T_CONV cimag (rc),
38	  T_CONV creal (rc2), T_CONV cimag (rc2));
39  CHECK(rc == rc2);
40  exit(0);
41}
42