Am 25.11.20 um 23:02 schrieb Maciej W. Rozycki:
The Fortran intrinsis like HUGE, EPSILON, SELECTED_REAL_KIND etc
would have to be handled correctly, both for simplification in
the front end and in the library.

Does the program

   print *,HUGE(1.0)
   print *,EPSILON(1.0)
end

print correct values?
  Well, it does not link, for the somewhat unsurprising reason of a missing
libgfortran runtime.

OK.

What you can do instead is to use the C interpoerability feature
to make a Fortran subroutine which does not depend on
libgfortran, like this:

subroutine read_val (r, d, i) bind(c)
  use iso_c_binding, only : c_float, c_double, c_int
  real(kind=c_float), intent(out) :: r
  real(kind=c_double), intent(out) :: d
  integer(kind=c_int), intent(out) :: i
  r = huge(1._c_float)
  d = huge(1._c_double)
  i = selected_real_kind(6)
end subroutine read_val

and then call it from C, like this:

#include <stdio.h>

void read_val (float *, double *, int *);

int main ()
{
  float r;
  double d;
  int i;
  read_val (&r, &d, &i);
  printf ("r = %e d = %e i = %d\n", r, d, i);
  return 0;
}

On my (IEEE) box, this prints

r = 3.402823e+38 d = 1.797693e+308 i = 4

so if you have a working printf (or some other way to display
floating-point-variables) for C, you can examine the
values.

Best regards

        Thomas

Reply via email to