cls_float.c 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /* Area: closure_call
  2. Purpose: Check return value float.
  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_float_fn(ffi_cif* cif __UNUSED__, void* resp, void** args,
  9. void* userdata __UNUSED__)
  10. {
  11. *(float *)resp = *(float *)args[0];
  12. printf("%g: %g\n",*(float *)args[0],
  13. *(float *)resp);
  14. }
  15. typedef float (*cls_ret_float)(float);
  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. float res;
  23. cl_arg_types[0] = &ffi_type_float;
  24. cl_arg_types[1] = NULL;
  25. /* Initialize the cif */
  26. CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 1,
  27. &ffi_type_float, cl_arg_types) == FFI_OK);
  28. CHECK(ffi_prep_closure_loc(pcl, &cif, cls_ret_float_fn, NULL, code) == FFI_OK);
  29. res = ((((cls_ret_float)code)(-2122.12)));
  30. /* { dg-output "\\-2122.12: \\-2122.12" } */
  31. printf("res: %.6f\n", res);
  32. /* { dg-output "\nres: \-2122.120117" } */
  33. exit(0);
  34. }