Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29258 Discussions

naming constraints for overloading routines

forall
Beginner
680 Views
When using INTERFACE blocks to overload multiple names onto a generic name, the routines must have different argument lists, which makes sense. However, I recall very clearly reading somewhere in some 'reputable' standard-type book that you can overload an elemental routine with same argument list as a non-elemental routine, in which case the non-elemental is given priority for scalar args, and the elemental is used for non-scalar cases. I cannot seem to find this info anywhere, but both CVF/IVF allow me to do this overload (which is beneficial for me). Any comments?
0 Kudos
5 Replies
Steven_L_Intel1
Employee
680 Views
The standard calls for this. The Language Reference contains abbreviated rules and you'd have to study the full text of the standard, as amended by "Corrigendum 1", to see that this is the correct behavior.
0 Kudos
forall
Beginner
680 Views
Steve, just to be sure I understood you correctly, when you say "the standard calls for this" you mean the standard requires the compiler to allow overloading 2 procedures with identical argument list provided one is elemental and the other is not?

incidentally, is the F-95 standard anywhere online? I had a quick look and the best I could find was a copy I would have to pay for...
0 Kudos
Steven_L_Intel1
Employee
680 Views
The actual standard is not online for free, but there is a "working draft" that is essentially identical. I'm not sure offhand where it is right now. But this particular issue was clarified in "Corrigendum 1", a collection of interpretations to the standard. Here is what it says now:

14.1.2.4.1 Resolving procedure references to names established to be generic

(1) If the reference is consistent with a non-elemental reference to one of the specific interfaces of a generic interface that has the name and either is in the scoping unit in which the reference appears or is made accessible by a USE statement in the scoping unit, the reference is to the specific procedure in that interface block that provides that interface. The rules in 14.1.2.3 ensure that there can be at most one such specific procedure.

(2) If (1) does not apply, if the reference is consistent with an elemental reference to one of the specific interfaces of a generic interface that has that name and either is in the scoping unit in which the reference appears or is made accessible by a USE statement in the scoping unit, the reference is to the specific elemental procedure in that interface block that provides that interface. The rules in 14.1.2.3 ensure that there can be at most one such specific procedure.
0 Kudos
Hirchert__Kurt_W
New Contributor II
680 Views
I apologize if this reply is a duplicate: I originally replied a couple of days ago and that reply has not yet appeared on the board, so I am attempted to reproduce that reply.

The rules in 14.1.2.3 are intended to prevent 2 specific routines from having ambiguous argument lists. In particular, they do not allow two specific routines to have identical argument lists. There is no special allowance in 14.1.2.3 for one routine being elemental and one being non-elemental.

The text Steve cited from 14.1.2.4.1 covers a slightly different case. Imagine, for example, a generic in which the first specific is elemental with a single real argument and the seecond (non-elemental) specific has a single one-dimension real argument. 14.1.2.3 allows this, because of the difference in rank, but the elemental specific can also accept a one-dimensional argument, so the cited text from 14.1.2.4.1 states that in such a case, a reference to the generic with a one-dimensional argument is a reference to the non-elemental specific.


As a general rule, official standards are not available free (on-line or otherwise) because selling copies of those standards is one of the ways organizations such as ANSI and ISO make the money they need to stay in business, but the technical committees that develop those standards often make their drafts freely available during the development process. The final such draft often differs from the official standard only in details such as the words in page headers and footers and the content of non-binding front matter such as the title page. I believe the final draft of Fortran 95 was J3/97-007r2. It may still be available on www.j3-fortran.org.
0 Kudos
Steven_L_Intel1
Employee
680 Views
hirchert is correct - my apologies for the misunderstanding.
0 Kudos
Reply