/js/src/ctypes/libffi/testsuite/libffi.call/return_fl.c

http://github.com/zpao/v8monkey · C · 35 lines · 23 code · 5 blank · 7 comment · 3 complexity · 8cb25f1d27b06c6ca0ce529b04ae3c47 MD5 · raw file

  1. /* Area: ffi_call
  2. Purpose: Check return value float.
  3. Limitations: none.
  4. PR: none.
  5. Originator: <andreast@gcc.gnu.org> 20050212 */
  6. /* { dg-do run } */
  7. #include "ffitest.h"
  8. static float return_fl(float fl)
  9. {
  10. return 2 * fl;
  11. }
  12. int main (void)
  13. {
  14. ffi_cif cif;
  15. ffi_type *args[MAX_ARGS];
  16. void *values[MAX_ARGS];
  17. float fl, rfl;
  18. args[0] = &ffi_type_float;
  19. values[0] = &fl;
  20. /* Initialize the cif */
  21. CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 1,
  22. &ffi_type_float, args) == FFI_OK);
  23. for (fl = -127.0; fl < 127; fl++)
  24. {
  25. ffi_call(&cif, FFI_FN(return_fl), &rfl, values);
  26. printf ("%f vs %f\n", rfl, return_fl(fl));
  27. CHECK(rfl == 2 * fl);
  28. }
  29. exit(0);
  30. }