[J3] type definitions
Malcolm Cohen
malcolm at nag-j.co.jp
Sun Aug 14 01:14:25 UTC 2022
The double precision X is inaccessible within the type definition, so KIND(X) is a reference to the type parameter. I would not consider that to be surprising.
That means that the program fragment may conform, but only if the kind type parameter value of default integer kind is a valid kind type parameter for type real. That is not required by the standard. Indeed, the NAG compiler offers an option to make all kind type parameter values unique, specifically to make it possible to catch mistakes where a kind type parameter of one type (perhaps gotten by SELECTED_INT_KIND) is used to specify the kind of a different type (e.g. REAL).
Cheers,
--
..............Malcolm Cohen, NAG Oxford/Tokyo.
From: J3 <j3-bounces at mailman.j3-fortran.org> On Behalf Of Vipul Parekh via J3
Sent: Sunday, August 14, 2022 7:37 AM
To: General J3 interest list <j3 at mailman.j3-fortran.org>
Cc: Vipul Parekh <parekhvs at gmail.com>
Subject: Re: [J3] type definitions
On Sat, Aug 13, 2022 at 4:46 PM Van Snyder via J3 <j3 at mailman.j3-fortran.org <mailto:j3 at mailman.j3-fortran.org> > wrote:
..
I don't think the reference to KIND(X) in the second example is a reference to the to-be-defined component. There is no syntax to reference a component of a type from within the type, or indeed anywhere else. Only the components of objects of the type can be accessed, and then they need the <designator>% before the component name. ..
On that notion, consider the following program where the complexity of a type parameter comes into play as opposed to a type component:
double precision :: x !<-- with or without this line
type :: t(x)
integer, kind :: x = 1
real(kind=kind(x)) :: r
end type
type(t) :: a
print *, "kind(a%r) = ", kind(a%r)
end
I think it conforms but the practitioner may possibly be surprised by the results!
Vipul Parekh
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.j3-fortran.org/pipermail/j3/attachments/20220814/04f507c2/attachment-0001.htm>
More information about the J3
mailing list