- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
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
Link Copied
2 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Steve,
Thanks -- without -C and with -xW, this worked. I need to try out if this works for other data types too.
Thanks -- without -C and with -xW, this worked. I need to try out if this works for other data types too.

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