Question

With fortran-iso-c-binding I can interface C functions and get variables of types like

real(c_float)
integer(c_int)

But in the rest of a program I would like to use basic types (simply because I do not want to replace many real variables with real(c_float) variables just because of one interface function)

Is there a safe, platform/compiler independent and reliable way how to cast fortran-iso-c-binding types back to fortran (primitive) types? equivalent to REAL()

Was it helpful?

Solution

The REAL intrinsic is what you want. Or equivalently, simple assignment.

REAL(C_FLOAT) :: r_c
REAL :: r_default
r_default = r_c

If the value being converted is out of range for the destination kind, your program is non-conforming.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top