gah4 <
ga...@u.washington.edu> schrieb:
> On Sunday, January 24, 2021 at 1:53:38 AM UTC-8, Thomas Koenig wrote:
>> Peter Klausler US <
pkla...@nvidia.com> schrieb:
>> > C708 requires things declared as CLASS to be dummy arguments,
>> > pointers, or allocatables. But there's no proscription against
>> > explicit shape dummy arguments that I can find in Fortran 2018,
>> > and I looked at every instance of the phrases related to assumed
>> > shape and explicit shape.
>
>> That settles it, then.
>
>> >It might be an implementation limitation
>> > in NAG, since the type is coming in a descriptor but the bounds
>> > are not.
>
>> Probably something that is fixable - if a calling convention
>> is rejected, it is always possible to fix it with a different
>> calling convention :-)
>
> But what does it mean?
>
> Usual arrays in Fortran are of things that are known size at compile
> time,
Not necessarily.
It is, for example, possible to have an array of characters
of length that is unknown at compile time. For example:
subroutine foo(a)
character(len=*), dimension(:) :: a
print *,len(a)
print *,size(a)
end subroutine foo
You can also have an allocatable array of characters:
character(len=:), dimension(:) :: b
and give it a length via an ALLOCATE statement.
>or are references in some way to things stored somewhere else.
It is not possible in Fortran to have an array of pointers. You can
have arrays of derived types which contain pointers.
> In Java, there are primitive types and references, such that everything
> that isn't a primitive type is a reference (you aren't supposed to call
> them pointers, but otherwise). Arrays are objects, such that N
> dimensional arrays are actually N-1 dimensional arrays of array
> references, and 1 dimensional arrays of the actual type.
That is a big difference to Fortran. An array is, in the words
of the standard (3.3), a
# set of scalar data, all of the same type and type parameters,
# whose individual elements are arranged in a rectangular pattern
> There is no type that is an array of contiguously allocated things,
> other than primitive types. (byte, char, short, int, long, float, double, boolean)
That is different to what Fortran does, as you can see from the above
definition.
> Maybe I don't understand Fortran class well enough, but it isn't so
> obvious how arrays of them work.
As written above, all elements of a Fortran array have the same
type.
Not knowing Java, I cannot really draw an analogy between Fortran
and Java. I suspect a Java class to be somewhat different from
a Fortran class. Just some points:
In Fortran, you declare a derived type. You can extend a derived
type, and you can bind procedures to it (which gives you type-bound
procedures).
If you declare a variable to be the class of the same type, it
means that that variable can be of the correspoding type, or of
some type that has extended the original type. However, you can
only declare class variables if they are pointers, allocatables
or dummy variables.
So, if you have
module x
type foo
integer :: i
end type foo
contains
subroutine bar(a)
class(foo), dimension(:) :: a
means that you can pass a 1d- array of type(foo) variables, or of
variables of a type that has been derived from type foo, to a.
All of elements have to have the same type.