* es.po: Update.
[official-gcc.git] / libffi / testsuite / libffi.complex / cls_complex_struct.inc
blobdf8708d1c4f98ddbaceb7a337921fef0ceee4eed
1 /* -*-c-*- */
2 #include "ffitest.h"
3 #include <complex.h>
5 typedef struct Cs {
6   _Complex T_C_TYPE x;
7   _Complex T_C_TYPE y;
8 } Cs;
10 Cs gc;
12 void
13 closure_test_fn(Cs p)
15   printf("%.1f,%.1fi %.1f,%.1fi\n",
16          T_CONV creal (p.x), T_CONV cimag (p.x),
17          T_CONV creal (p.y), T_CONV cimag (p.y));
18   gc = p;
21 void
22 closure_test_gn(ffi_cif* cif __UNUSED__, void* resp __UNUSED__,
23                 void** args, void* userdata __UNUSED__)
25   closure_test_fn(*(Cs*)args[0]);
28 int main(int argc __UNUSED__, char** argv __UNUSED__)
30   ffi_cif cif;
32   void *code;
33   ffi_closure *pcl = ffi_closure_alloc(sizeof(ffi_closure), &code);
34   ffi_type *cl_arg_types[1];
36   ffi_type ts1_type;
37   ffi_type* ts1_type_elements[4];
39   Cs arg = { 1.0 + 11.0 * I, 2.0 + 22.0 * I};
41   ts1_type.size = 0;
42   ts1_type.alignment = 0;
43   ts1_type.type = FFI_TYPE_STRUCT;
44   ts1_type.elements = ts1_type_elements;
46   ts1_type_elements[0] = &T_FFI_TYPE;
47   ts1_type_elements[1] = &T_FFI_TYPE;
48   ts1_type_elements[2] = NULL;
50   cl_arg_types[0] = &ts1_type;
52   /* Initialize the cif */
53   CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 1,
54                      &ffi_type_void, cl_arg_types) == FFI_OK);
56   CHECK(ffi_prep_closure_loc(pcl, &cif, closure_test_gn, NULL, code) == FFI_OK);
58   gc.x = 0.0 + 0.0 * I;
59   gc.y = 0.0 + 0.0 * I;
60   ((void*(*)(Cs))(code))(arg);
61   /* { dg-output "1.0,11.0i 2.0,22.0i\n" } */
62   CHECK (gc.x == arg.x && gc.y == arg.y);
64   gc.x = 0.0 + 0.0 * I;
65   gc.y = 0.0 + 0.0 * I;
66   closure_test_fn(arg);
67   /* { dg-output "1.0,11.0i 2.0,22.0i\n" } */
68   CHECK (gc.x == arg.x && gc.y == arg.y);
70   return 0;