- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi everyboy,
somebody gave me following source.
program main
implicit none
real(8)
x, y, zx = 1.5d0
y = 1.2d0
call
fkt(x,y)end
program mainfunction
fkt(a1, a2)implicit none
real(8)
fkt, a1, a2fkt = a1 * a2
end function
fktI was very surprised when I saw
- that the code was compiled without errors,
- that there were no linker errors,
- 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
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.

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