[ABI PATCH] static anonymous unions of function scope
[official-gcc.git] / libffi / testsuite / libffi.complex / complex.inc
blob515ae3e60deab8ff012a3adf516d67fcaf637338
1 /* -*-c-*-*/
2 #include "ffitest.h"
3 #include <complex.h>
5 static _Complex T_C_TYPE f_complex(_Complex T_C_TYPE c, int x, int *py)
7   c = -(2 * creal (c)) + (cimag (c) + 1)* I;
8   *py += x;
10   return c;
13 int main (void)
15   ffi_cif cif;
16   ffi_type *args[MAX_ARGS];
17   void *values[MAX_ARGS];
19   _Complex T_C_TYPE tc_arg;
20   _Complex T_C_TYPE tc_result;
21   int tc_int_arg_x;
22   int tc_y;
23   int *tc_ptr_arg_y = &tc_y;
25   args[0] = &T_FFI_TYPE;
26   args[1] = &ffi_type_sint;
27   args[2] = &ffi_type_pointer;
28   values[0] = &tc_arg;
29   values[1] = &tc_int_arg_x;
30   values[2] = &tc_ptr_arg_y;
32   /* Initialize the cif */
33   CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 3,
34                      &T_FFI_TYPE, args) == FFI_OK);
36   tc_arg = 1 + 7 * I;
37   tc_int_arg_x = 1234;
38   tc_y = 9876;
39   ffi_call(&cif, FFI_FN(f_complex), &tc_result, values);
41   printf ("%f,%fi %f,%fi, x %d 1234, y %d 11110\n",
42           T_CONV creal (tc_result), T_CONV cimag (tc_result),
43           T_CONV creal (2.0), T_CONV creal (8.0), tc_int_arg_x, tc_y);
45   CHECK (creal (tc_result) == -2);
46   CHECK (cimag (tc_result) == 8);
47   CHECK (tc_int_arg_x == 1234);
48   CHECK (*tc_ptr_arg_y == 11110);
50   exit(0);