Home > Archive > Fortran > October 2006 > can internal procedures be overloaded?
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
can internal procedures be overloaded?
|
|
|
| Hi there. I am learning Fortran, and come up with this dumb question
now.
| |
| Richard Maine 2006-10-02, 4:04 am |
| qsc <qingshan.chen@gmail.com> wrote:
> Hi there. I am learning Fortran, and come up with this dumb question
> now.
By "can they be overloaded", I assume you mean to ask whether they can
be specific procedures in a generic. That's the only interpretation I
can give it that makes sense to me. I would probably call that being
part of an overload instad of being overloaded, but that might just be
how I use the terms. Neither is formally Fortran terminology.
I wouldn't say it was at all dumb. I think they can in f2003, though I'd
have to go read carefully to be sure. I can't see why there would be a
restriction against it. In f90/f95 they can't because of idiosyncracies
in the syntax of interface blocks. Namely, there are two things that you
can put in a generic interface block.
1. Interface bodies. You can't use those for internal procedures for the
same reason that you can't for module procedures - the procedure already
has an explicit interface.
2. Module procedure statements. You acn't use those because they are
allowed only for module procedures.
In f2003, the module procedure statement is generalized to be just a
procedure statement (with the optional module qualifier for
compatibility). Thus it can be used for the purpose. It seem silly for
that statement to have ever been specific to module procedures. I
suspect it was just limitted to module procedures because that's the
only case where the original drafters thought it could be useful; if so,
they missed several.
--
Richard Maine | Good judgement comes from experience;
email: last name at domain . net | experience comes from bad judgement.
domain: summertriangle | -- Mark Twain
| |
| Brooks Moses 2006-10-02, 4:04 am |
| qsc wrote:
> Hi there. I am learning Fortran, and come up with this dumb question
> now.
Do you actually mean "internal procedures" (which are user-defined
procedures that are inside program units), or is that perhaps a typo for
"intrinsic procedures" (which are things like COS(), SUM(), etc.)?
If you mean the latter, yes, it's quite possible to overload intrinsic
procedures to apply to user-defined types. It's no different from
defining (or extending) any other generic procedure name:
module myexample
type mytype
...
end type
interface cos
module procedure mycos
end interface
contains
function mycos(t)
type(mytype), intent(in) :: t
...
end function
end module
Hope this helps,
- Brooks
--
The "bmoses-nospam" address is valid; no unmunging needed.
| |
|
|
Hi,
Thank you both for the replies. You have gave sufficient information
for me to get rid of that dumb question. Thanks a lot!
| |
| Richard Maine 2006-10-02, 7:03 pm |
| Brooks Moses <bmoses-nospam@cits1.stanford.edu> wrote:
> Do you actually mean "internal procedures" (which are user-defined
> procedures that are inside program units), or is that perhaps a typo for
> "intrinsic procedures" (which are things like COS(), SUM(), etc.)?
>
> If you mean the latter, yes, it's quite possible to overload intrinsic
> procedures to apply to user-defined types.
Oh. I didn't think about that possible misstatement ("internal" for
"intrinsic"), but good call. And, in fact, there's another variant of
the question along those lines.
As you say, there is the question about adding user extensions to an
generic intrinsic. That's actually not quite the same as other generics.
The syntax is the same, but the resolution rules are different... and
complicated. Fortunately, the complications only come up in horribly
messy situations that you never ought to be in in the first place (but
the standard has to define what happens in every case - even ugly edge
ones). You will *NOT* be able to think of the edge cases, no matter how
hard you try; I ought to lay money on it. :-) (But I won't). In fact,
it would take me a while to reconstruct one. Hint - host association
gets involved.
The second question along those lines is the other way around. Can you
add an intrinsic as a specific of a user generic. I think you can in
f2003, as long as it is a specific intrinsic. Same isssues involved
there as with adding an internal procedure as a specific for a user
generic.
--
Richard Maine | Good judgement comes from experience;
email: last name at domain . net | experience comes from bad judgement.
domain: summertriangle | -- Mark Twain
|
|
|
|
|