5

Has Fortran ever gotten around to handling subroutine argument lists with arbitrary length, like C can do? (BTW, "present" isn't going to work for what I am trying to do.) Thanks.

bob.sacamento
  • 6,283
  • 10
  • 56
  • 115
  • 1
    [This other question](https://stackoverflow.com/q/19672687/3157076) is about interoperability with C procedures with variable arguments. It is relevant but doesn't explicitly say "no" in the more general case. – francescalus Aug 30 '18 at 15:02
  • @francescalus OK. Thanks. – bob.sacamento Aug 30 '18 at 15:04
  • Are the variadic arguments possibly (fortunately) of the same type? (e.g. all are reals etc) Then we may be able to use an array argument (though not a general solution...) – roygvib Aug 30 '18 at 19:29
  • @roygvib Actually, yes, all arguments should be of the same type. Suggestions? Thanks. – bob.sacamento Aug 30 '18 at 20:21
  • 1
    Not anything special, but just passing an array as "call mysub( arg1, arg2, [ x1, x2, x3 ] )" etc, and define the routine such that the 3rd argument (in this case) is declared as "real, intent(in) :: xs( : )" etc. If we want to modify the actual args, it may be necessary to create an independent array (not a temporal one) and pass it in the same way (here intent(in) is not attached). – roygvib Aug 31 '18 at 03:25
  • Variadic arguments always need an extra parameter to describe the type. You can get around it with transfer functions and arrays but it is quite clumsy. Optional arguments may be what you are looking for. – cup Sep 01 '18 at 07:46

1 Answers1

5

There are no such subroutines in Fortran.

The syntax rule for a subroutine statement in Fortran 2008 is (12.6.2.3, R1235):

[ prefix ] SUBROUTINE subroutine-name [ ( [ dummy-arg-list ] ) [ proc-language-binding-spec ] ]

where dummy-arg-list is a list (in assumed syntax rule terms) of dummy-args. A dummy-arg is (R1235) either a name or a literal *.

[Before we get too excited about the possibility of variadic support, the * refers, of course, to an alternate return indicator.]

A list (R101) still refers to a well-defined (at source time) number of items.

There is a stated restriction regarding interoperability with C, that (15.3.7) the C prototype

... does not have variable arguments as denoted by the ellipsis (...)

Similar arguments apply to (Fortran) functions.

francescalus
  • 30,576
  • 16
  • 61
  • 96