Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29263 Discussions

ifc 7.1: "Call" a function raises run-time error

vsbabu
Beginner
505 Views
I know this is not how Fortran is supposed to be, but wondering 7.1 can be told to ignore these kind of mistakes -- I inherited tons of code that follows this kind of programming :-(

Sample code:
PROGRAM FUNC_CALLED_AS_SUB
INTEGER X, Y, Z

X = 4
Y = 3

PRINT *, ' Try to call a function as a sub', X, Y
PRINT *, ' Function addints adds two values, X and Y', X, Y

C The code below is proper; it compiles and works as expected
C PRINT *, ' Z = addints(X, Y) should work just fine'
C Z = addints(X, Y)
C PRINT *, 'Value is ', Z

PRINT *, ' CALL addints(X, Y) should give a compilation error'
C G77 gives a compiler error; IFC7.1 gives nothing at compile time
C but gives an error at run-time (if -C is enabled at compile time)
C that says you can't call a function. If -C is not specified, it
C just gives an "Address Error"
CALL addints(X, Y)

END PROGRAM

REAL FUNCTION addints(one, two)
INTEGER :: one, two
INTEGER ret
ret = one + two
PRINT *, 'Value inside is ', ret
addints = ret
RETURN
END FUNCTION addints ! end of addints

Message Edited by vsbabu@gmail.com on 01-19-2005 01:20 AM

0 Kudos
2 Replies
Steven_L_Intel1
Employee
505 Views
This one is very nasty. You're not going to get it to work using generic X86 code because it corrupts the floating point stack to CALL a function whose result is returned on the floating point stack. It may work if you compile -xW so that SSE2 is used.

Message Edited by sblionel on 01-19-2005 09:04 AM

0 Kudos
vsbabu
Beginner
505 Views
Steve,

Thanks -- without -C and with -xW, this worked. I need to try out if this works for other data types too.
0 Kudos
Reply