Salut Dominique, moin Richard, hello all,

(Answering Richard's question from PR33330.)
Dominique Dhumieres wrote:
>> Btw, is it mandated by the fortran standard to pass a scalar as array
>> reference?
>>     
> Does anyone knows the answer? or should it be asked on comp.lang.fortran?
>   

The standard mandates that (when the dummy argument has no VALUE
attribute) variables are passed as reference; I'm pretty sure that the
rest is implementation dependent. I think the question arose form:

   character :: my_char

which is a scalar character variable which takes exactly one character.
However, the following is also a scalar variable:

   character(len=10) :: my_char

which contains 10 characters. It has the same storage size as an array
with ten elements with one character each:

  character(len=1), dimension(10) :: my_char

As a scalar character variable with len > 1 needs an array reference, it
is quite natural to pass also a scalar variable with length 1 as array
reference.

I think the standard also allows to pass it as non-array reference,
which happens (for obvious reasons) if one uses C Bindings. (In this
case the standard mandates len=1; for strings one has thus to use an array.)


Hmm, thinking it over, I think on can say that the standard mandates
that an array reference is passed. Let's assume two functions,
expecting, respectively,

  character(len=1) :: arg
  character(len=*) :: arg

(len=* allows for any lengths; the length is passed as an additional
argument in both cases.)

In the main program I do now:
  call mySubroutine( 'a' )

in order to decide whether one needs to pass an array reference or not,
one needs to know whether len=1 or len=*. This is only possible if one
knows the explicit interface (= function definition); but Fortran allows
also implicit interfaces (i.e. "assume mySubroutine exists, it returns
VOID and takes 0 to oo arguments of a certain but unknown type").

Tobias

Reply via email to