Multiple Return Values in Co-array Fortran
Co-array Fortran supports multiple return values through the use of derived types. Here’s an example demonstrating this feature:
In this Co-array Fortran code:
We define a derived type
dual_int
to simulate multiple return values.The
vals()
function returns adual_int
object containing two integers.In the
main
subroutine, we demonstrate how to use these multiple return values:- First, we assign both values to separate variables.
- Then, we show how to use only one of the returned values.
The
print *
statements are used to output the results.
To run this program, you would typically save it in a file (e.g., multiple_return_values.f90
), compile it, and then execute the resulting binary:
Note that Co-array Fortran doesn’t have a direct equivalent to Go’s blank identifier _
. Instead, we simply don’t use the component we’re not interested in.
While Co-array Fortran doesn’t have built-in support for multiple return values like Go, using derived types allows us to achieve similar functionality in a type-safe manner.