2017-08-28 Richard Biener <rguenther@suse.de>
[official-gcc.git] / libffi / testsuite / libffi.complex / cls_complex.inc
blobf9374044e8781a4b6f8ff2a685bb43a7199420d9
1 /* -*-c-*- */
2 #include "ffitest.h"
3 #include <complex.h>
5 static void cls_ret_complex_fn(ffi_cif* cif __UNUSED__, void* resp, void** args,
6                               void* userdata __UNUSED__)
7  {
8    _Complex T_C_TYPE *pa;
9    _Complex T_C_TYPE *pr;
10    pa = (_Complex T_C_TYPE *)args[0];
11    pr = (_Complex T_C_TYPE *)resp;
12    *pr = *pa;
14    printf("%.6f,%.6fi: %.6f,%.6fi\n",
15           T_CONV creal (*pa), T_CONV cimag (*pa),
16           T_CONV creal (*pr), T_CONV cimag (*pr));
17  }
18 typedef _Complex T_C_TYPE (*cls_ret_complex)(_Complex T_C_TYPE);
20 int main (void)
22   ffi_cif cif;
23   void *code;
24   ffi_closure *pcl = ffi_closure_alloc(sizeof(ffi_closure), &code);
25   ffi_type * cl_arg_types[2];
26   _Complex T_C_TYPE res;
28   cl_arg_types[0] = &T_FFI_TYPE;
29   cl_arg_types[1] = NULL;
31   /* Initialize the cif */
32   CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 1,
33                      &T_FFI_TYPE, cl_arg_types) == FFI_OK);
35   CHECK(ffi_prep_closure_loc(pcl, &cif, cls_ret_complex_fn, NULL, code)  == FFI_OK);
37   res = (*((cls_ret_complex)code))(0.125 + 128.0 * I);
38   printf("res: %.6f,%.6fi\n", T_CONV creal (res), T_CONV cimag (res));
39   CHECK (res == (0.125 + 128.0 * I));
41   exit(0);