Laurent Hill said:
> I have a problem with the interpretation of the following code:
>
> program typefield1
> type T1
> integer :: v
> end type T1
> type T2
> type(T1) :: t1 ! what is T1 here ?
> end type T2
> type(T2) :: v
> v%t1%v=10
> print *, v%t1%v
> end program typefield1
>
> Is this legal ?
Yes.
> My interpretation would be that it isn't, since in the scope of
> the definition of T2, T1 refers to the field T1, not to the type.
Not so.
According to section 14.1.2 of the Fortran standard, type names are names of
class 1 whereas component names are names of class 2. It further states:
"A name that identifies a local entity of one class may be used to identify
a local entity of another class."
> Nag compiler rejects it, but the SUN compiler accept the code, and
This was a bug in 2.0, which was fixed in 2.1. The 2.1 compiler was released
in late 1994 so you are using a *very* old version.
> If it is legal, then is the following example also legal ?
> (it is rejected by the sun compiler)
It is not legal.
> subroutine typefield2
> type T1
> integer :: v
> end type T1
> call inner
> contains
> subroutine inner
> type(T1)::t1
> t1%v=10
> print *, t1%v
> end subroutine inner
> end subroutine typefield2
Again according to section 14.1.2, variable names are class 1 names (just like
derived-type names). It further states:
"...a name that identifies a local entity of one class shall not be used to
identify another local entity of the same class..."
Therefore since T1 the type and T1 the variable are local entities of the same
class, they must have differing names.
Cheers,
--
...........................Malcolm Cohen, NAG Ltd., Oxford, U.K.
([log in to unmask])
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|