- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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?
Link Copied
5 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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...
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...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
hirchert is correct - my apologies for the misunderstanding.

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page