(j3.2006) derived types with type parameters are different
Jim Xia
jimxia
Thu Jul 24 09:51:06 EDT 2008
j3-bounces at j3-fortran.org wrote on 07/24/2008 02:20:35 AM:
> Jim Xia wrote:
> >
> > >
> > > MODULE M1
> > > TYPE T(N)
> > > INTEGER(KIND=4), KIND :: N
> > > SEQUENCE
> > > REAL A(N)
> > > END TYPE
> > > TYPE(T(4)) :: X
> > > END
> > >
> > > MODULE M2
> > > TYPE T(N)
> > > INTEGER(KIND=4), KIND :: N
> > > SEQUENCE
> > > REAL A(N+0)
> > > END TYPE
> > > TYPE(T(4)) :: Y
> > > END
> > >
> > > In this case, should X and Y be considered to have the same
> > > type? I think not, but I find no language in the standard
> >
> > Why would you think x and y are of different types? They look to be
the
> > same type to me.
>
> 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.
Cheers,
Jim Xia
RL Fortran Compiler Test
IBM Toronto Lab at 8200 Warden Ave, Markham, On, L6G 1C7
Phone (905) 413-3444 Tie-line 313-3444
email: jimxia at ca.ibm.com
D2/YF7/8200 /MKM
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://j3-fortran.org/pipermail/j3/attachments/20080724/fa39fc8c/attachment.html
More information about the J3
mailing list