Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.

overloading intrinsic functions

Izaak_Beekman
New Contributor II
1,400 Views
Does anyone know how to overload intrinsic functions? Preeferably using f95 comnpliant syntax if possible. Thanks.
0 Kudos
2 Replies
Steven_L_Intel1
Employee
1,400 Views
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.
0 Kudos
Izaak_Beekman
New Contributor II
1,400 Views
Thats easy! I was anticipating that

INTERFACE sqrt

would cause a name conflict with the intrinsic sqrt or clobber the intrinsic sqrt.
Thanks steve.
0 Kudos
Reply