Variadic Functions in Fortran
Variadic functions can be called with any number of trailing arguments. For example, fmt.Println
is a common variadic function.
Here’s a function that will take an arbitrary number of int
s as arguments.
Within the subroutine, the type of nums
is equivalent to integer array
. We can call size(nums)
, iterate over it with a loop, etc.
Variadic functions can be called in the usual way with individual arguments.
If you already have multiple arguments in an array, apply them to a variadic function using array slicing like this.
Another key aspect of functions in Fortran is their ability to handle array arguments and perform operations over them efficiently.