. vs. %

. vs. %

Lets talk about it. You do not like %? Why? Because in some another languages for the same purpose . is used Im disagree with it. I understand that . gives nice vision but Fortran is not C-kind language like C++, C#, Java and so on. I think it is not correct to use dot in this kind of case. If you have a look to ISO/IEC 1539-1:2004(E) youll find that even there dot isnt used for this:

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

of part-name.

Why so? I do not think its because of conservatism. Fortran is Fortran and we cant sometimes just simply add new feature from another language even dot. I prepared code for this. Lets see:

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. )

	function OrVectors( vect1, vect2 )
		type(Vector) :: OrVectors
		type(Vector), intent(in) :: vect1, ve
		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.

2 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

The "." separator was an extension we (then DEC Fortran) created in 1985, introduced with VAX FORTRAN V4 as part of a new feature referred to as STRUCTURE/RECORD. This feature became very popular and was widely implemented. Our compiler had a simple rule for resolving ambiguity in the case of something like A.OR.B - if A had a field called OR, then that's what it was, otherwise it was the operator .OR..

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 %.

Steve - Intel Developer Support

Leave a Comment

Please sign in to add a comment. Not a member? Join today