cls_double.c 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /* Area: closure_call
  2. Purpose: Check return value double.
  3. Limitations: none.
  4. PR: none.
  5. Originator: <andreast@gcc.gnu.org> 20030828 */
  6. /* { dg-do run } */
  7. #include "ffitest.h"
  8. static void cls_ret_double_fn(ffi_cif* cif __UNUSED__, void* resp, void** args,
  9. void* userdata __UNUSED__)
  10. {
  11. *(double *)resp = *(double *)args[0];
  12. printf("%f: %f\n",*(double *)args[0],
  13. *(double *)resp);
  14. }
  15. typedef double (*cls_ret_double)(double);
  16. int main (void)
  17. {
  18. ffi_cif cif;
  19. void *code;
  20. ffi_closure *pcl = ffi_closure_alloc(sizeof(ffi_closure), &code);
  21. ffi_type * cl_arg_types[2];
  22. double res;
  23. cl_arg_types[0] = &ffi_type_double;
  24. cl_arg_types[1] = NULL;
  25. /* Initialize the cif */
  26. CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 1,
  27. &ffi_type_double, cl_arg_types) == FFI_OK);
  28. CHECK(ffi_prep_closure_loc(pcl, &cif, cls_ret_double_fn, NULL, code) == FFI_OK);
  29. res = (*((cls_ret_double)code))(21474.789);
  30. /* { dg-output "21474.789000: 21474.789000" } */
  31. printf("res: %.6f\n", res);
  32. /* { dg-output "\nres: 21474.789000" } */
  33. exit(0);
  34. }