- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Does anyone know how to overload intrinsic functions? Preeferably using f95 comnpliant syntax if possible. Thanks.
Link Copied
2 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The same way you overload any generic function. For example:
[fortran]module overload
interface sqrt
module procedure char_sqrt
end interface
contains
function char_sqrt (x)
real :: char_sqrt
character(*), intent(in) :: x
real :: xr
read (x,*) xr
char_sqrt = sqrt(xr)
end function char_sqrt
end module overload
program test
use overload
print *, sqrt('2.0')
end[/fortran] The key is a generic interface that names the generic name of the intrinsic you want to overload. You can use a module procedure or an external procedure. The important part is that the extended generic not introduce any ambiguity - here, I gave SQRT a signature with a character argument.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thats easy! I was anticipating that
INTERFACE sqrt
would cause a name conflict with the intrinsic sqrt or clobber the intrinsic sqrt.
Thanks steve.
INTERFACE sqrt
would cause a name conflict with the intrinsic sqrt or clobber the intrinsic sqrt.
Thanks steve.
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