Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Fortran program calling C subroutine. How do I compile??

Status
Not open for further replies.

RamonetB

Technical User
Oct 20, 2003
4
US
Hello all you wonderful programmers, you!

I'm trying to recompile a piece of code that was not written by me. In it, there is a call to a subroutine "falloc." Now, as I understand, this is an intrinsic call in Compaq Digital Fortran 90 (helps setup memory allocation for arrays). However, I'm using Intel Fortran compiler V8.0 (with C++ .NET 2003 standard).

Recognizing that not everyone using CDF90, a subroutine written in C was provided. "void falloc_(values in here)"
Now, obviously, when I compile the fortran code I get an error to a missing external link "falloc."

How do I link the worlds of C and Fortran? I've done some research into past posts but the answer still isn't too clear.

Many thanks in advance.

-kirk
 
Hi Kirk,

I don't know about Intel fortan but I think that you have to declare that the function falloc_ you want to call uses the c calling convention. This can be don by declaring an explicit interface to this function and stating that this functions uses the c calling convention. In Compaq fortran this will be declared as :

Code:
interface
  integer function falloc_(arg1, arg2)
  !dec$ attributes c :: falloc_
  !dec$ attributes reference :: arg1 ! argument dependent
  !dec$ attributes reference :: arg2 ! argument dependent
    type declaration of arguments
  end function
end interface

You also may have do give an alias for this function. Did you have any module that already offers this explicit interface statements ?

Phil31 - ;-)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top