- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
6.1.2 Structure components
A structure component is part of an object of derived type; it may be referenced by an object
designator. A structure component may be a scalar or an array.
R612 data-ref is part-ref [ % part-ref ] ...
R613 part-ref is part-name [ ( section-subscript-list ) ]
C609 (R612) Each part-name except the rightmost shall be of derived type.
C610 (R612) Each part-name except the leftmost shall be the name of a component of the declared
type of the preceding part-name.
C611 (R612) If the rightmost part-name is of abstract type, data-ref shall be polymorphic.
C612 (R612) The leftmost part-name shall be the name of a data object.
C613 (R613) If a section-subscript-list appears, the number of section-subscripts shall equal the rank
module VectorType implicit none type Vector integer N type(log), pointer :: or end type Vector type log type(Vector) vect2 end type log interface operator( .or. ) module procedure OrVectors end interface operator( .or. ) contains function OrVectors( vect1, vect2 ) type(Vector) :: OrVectors type(Vector), intent(in) :: vect1, ve ct2 OrVectors%N = vect1%N + vect2%N !vect1%N = 3 -- not pass !vect1.N = 3 -- pass! end function OrVectors end module VectorType program Test use Modul implicit none type(Vector) vect1, vect2, vect3 type(log), target :: logic vect1%N = 1 vect2%N = 2 logic%vect2%N = 4 vect1%or => logic vect3 = vect1.or.vect2 print *, vect3%N read * end program Test
What does mean there vect1.or.vect2? Operation or components selection? IFC chose the second and have printed 4. But what if I wanted to use overloaded operator .or. which must give in result 3! So using dot in this use case are corruptly.
And notice the comments: !vect1%N = 3 -- not pass and !vect1.N = 3 -- pass!. This some kind of bug.
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
When Fortran 90 came along, the standards committee decided to use % as a separator instead. There are lots of arguments on both sides, but that's what it is. If you use % there is no ambiguity, but with . there is the additional issue of user-defined operators. But the compiler can extend the rule so that if it sees A.FOO.B, then if there is a user-defined operator .FOO. then it's the operator (this has to come first as otherwise a standard-conforming program could become invalid).
We could have decided to allow . only for user-defined types declared with STRUCTURE/RECORD, but we decided instead to make STRUCTURE/RECORD and derived types as interchangeable as possible, so you can use either . or %.
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page