(j3.2006) derived types with type parameters are different

Andy Vaught andyv
Thu Jul 24 11:56:36 EDT 2008


On Thu, 24 Jul 2008, Jim Xia wrote:

> > To expand on the point, consider the modules
> > 
> >        MODULE M1
> >          TYPE T(N)
> >            INTEGER(KIND=4), KIND :: N
> >            SEQUENCE
> >            REAL A(N+N)
> >          END TYPE
> >          TYPE(T(2)) :: X1
> >          TYPE(T(3)) :: X2
> >        END
> > 
> >        MODULE M2
> >          TYPE T(N)
> >            INTEGER(KIND=4), KIND :: N
> >            SEQUENCE
> >            REAL A(N*N)
> >          END TYPE
> >          TYPE(T(2)) :: Y1
> >          TYPE(T(3)) :: Y2
> >        END
> > 
> > In the case, would X1 and Y1 has the same type?  Would X2 and Y2?
> 
> The new example is quite different from your original one.  For the new 
> pair of T, the array size for component A has different dependence on the 
> type parameter value (N+N vs. N*N), therefore I wouldn't think two types 
> are the same.  For two sequence types to be the same type, they must have 
> the same memory layout for any pair of objects that having the same type 
> parameter values.  This condition can not be met between X2 and Y2 here. 
> However in your earlier case (N vs. N+0), regardless what N value you 
> choose for the two objects, X and Y, they will always be of the same size.

Robert's example didn't go far enough then.  How about:

        MODULE M1
          TYPE T(N)
            INTEGER(KIND=4), KIND :: N
            SEQUENCE
            REAL A((N-1)*N)
          END TYPE
          TYPE(T(2)) :: X1
          TYPE(T(3)) :: X2
        END

        MODULE M2
          TYPE T(N)
            INTEGER(KIND=4), KIND :: N
            SEQUENCE
            REAL A(N*N-N)
          END TYPE
          TYPE(T(2)) :: Y1
          TYPE(T(3)) :: Y2
        END

Is this the same type, ie, how much algebra does the compiler have to be
able to do?

   Andy




More information about the J3 mailing list