Mailing List Archive

Support open source code!


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

tlug: Calling C procedures from FORTRAN



>>>>> "VR" == Venkatesh Raghavan <raghavan@example.com> writes:

    VR> I am writing a FORTRAN program that calls C procedures. I am
    VR> using g77 and gcc compilers.  By default the g77 compiler
    VR> appends an _(underscore) to function and subroutine names. For
    VR> example my program call a C procedure as follows; CALL CPROC()

    VR> and I have to name the C procedure as cproc_()

Does this actually work?  I thought FORTRAN and C had different
calling conventions.  That's what those underscores are for,
preventing you from accidentally linking incompatible call sequences.

    VR> Is there any way/option for suppressing this addition of
    VR> underscore in FORTRAN so that C procedures can be called
    VR> directly (without adding an underscore).

In C++, if FORTRAN linkage is supported, you can do the following

#ifndef NAG_WRAPPER
#define NAG_WRAPPER
extern "fortran" {

/* prototypes for NAG routines go here */

}

This automatically generates the necessary thunks to make sure the
arguments are in the right order and alignment and so on.  I don't
know how you would do this in FORTRAN to call C.

-- 
University of Tsukuba                Tennodai 1-1-1 Tsukuba 305-8573 JAPAN
Institute of Policy and Planning Sciences       Tel/fax: +81 (298) 53-5091
__________________________________________________________________________
__________________________________________________________________________
What are those two straight lines for?  "Free software rules."
-------------------------------------------------------------------
Next Technical Meeting: February 13 (Sat), 12:30 place: Temple Univ.
** presentation: XEmacs, by Steven Baur and Martin Buchholz
Next Nomikai: March 19 (Fri), 19:30   Tengu TokyoEkiMae 03-3275-3691
-------------------------------------------------------------------
more info: http://tlug.linux.or.jp                     Sponsor: PHT


Home | Main Index | Thread Index

Home Page Mailing List Linux and Japan TLUG Members Links