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.

Call a function ?!?!

muppets
Beginner
549 Views

Hi everyboy,

somebody gave me following source.

program main

implicit none

real(8)

x, y, z

x = 1.5d0

y = 1.2d0

call

fkt(x,y)

print

*, x,y,z

end

program main

function

fkt(a1, a2)

implicit none

real(8)

fkt, a1, a2

fkt = a1 * a2

end function

fkt

I was very surprised when I saw

  1. that the code was compiled without errors,
  2. that there were no linker errors,
  3. that the resulting exe worked without crashes, errors or something similar.

There is a function fkt which is treated as a subroutine (via call ...) by the main program. Is this allowed in standard fortran or is it just a bug? I use Visual Studio 2003 and IVF 9.0.

Thank you in advance

muppets

0 Kudos
1 Reply
Steven_L_Intel1
Employee
549 Views

This is not legal Fortran, but the compiler can't tell because in the main program, there's nothing to indicate that fkt is a function. If you had called fkt in a loop, the program would have died after 8 or so iterations because this mismatch corrupts the floating point stack.

In the version of the compiler you have, it does allow, in some limited circumstances, calling a name known as a function. That has been tightened in version 9.1 so if the compiler knows it's a function, it must be referenced as a function.

0 Kudos
Reply