(j3.2006) type parameter scoping question
Bill Long
longb
Thu Nov 21 17:47:24 EST 2013
For this (intentionally perverse) program:
integer, parameter :: nasty=10
type foo(nasty)
integer, kind :: nasty = 3
integer (kind=nasty + nasty) :: n
end type
type(foo(4)) :: x
print *, kind(x%n)
end
What should happen? I'm seeing three different compiler behaviors:
1) Multiple errors at compile time because the PDT feature is not supported.
2) Compile with no errors; executes and prints 8.
3) Compile time error for an unsupported KIND for the integer N
(presumably either 20 or 6, with 20 being more likely).
The argument for compiler 2 is that the scope of the type parameter
nasty is the type definition, and in that scope valid uses of nasty
refer to the type parameter and not the named parameter of the same name
in the host scope.
The argument for compiler 3 appears to be that since the type parameter
and named constant are in different classes of local identifiers, they
can both used in the type definition. And the named parameter "wins".
I'm partial to the compiler 2 interpretation since it is not ambiguous,
and makes intuitive sense in that local host entities normally block
access to host entities with the same name. (Though that last argument
is usually applied to identifiers in the same class.) The compiler 3
interpretation seems to make it easy to render the type parameter
useless inside the type definition.
An alternative is to say that the code is not conforming at all. But
I'm not seeing the argument for that.
In any event, there are implementation conflicts. It would be
interesting to see how the Sun, IBM, and NAG compilers handle this
program - I don't have any of them installed locally.
Cheers,
Bill
--
Bill Long longb at cray.com
Fortran Technical Support & voice: 651-605-9024
Bioinformatics Software Development fax: 651-605-9142
Cray Inc./Cray Plaza, Suite 210/380 Jackson St./St. Paul, MN 55101
More information about the J3
mailing list