Mailing List Archive

Support open source code!


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

Re: tlug: Calling C procedures from FORTRAN



Hi,
Thanks for your reply. I just found a g77 option to avoid appending
_(underscore)
to C procedure calls. This makes it easier for me to make C procedure and
library call from my Fortran program. The g77 option is as shown below;

>g77 -fno-underscoring -fsource-case-preserve test.f

the "-fno-underscoring" is to avoid adding the underscore and
"-fsource-case-preserve"
is to preserve the case sensitivity in my Fortran program. I need to use the
"-fsource-case-preserve" flag since g77 converts subroutine names to lower
cases
and my C routines that have both upper and lower cases (eg. call R_open_driver
etc.)

Hope this helps people who want to try Fortran/C mixed programming.


Venkatesh Raghavan
Osaka City University



Stephen J. Turnbull wrote:

> >>>>> "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.
>



-------------------------------------------------------------------
Next Nomikai: March 19 (Fri), 19:30  Tengu TokyoEkiMae 03-3275-3691
Next Technical Meeting: April 10 (Sat), 12:30   place: Temple Univ.
-------------------------------------------------------------------
more info: http://tlug.linux.or.jp                     Sponsor: PHT

Home | Main Index | Thread Index

Home Page Mailing List Linux and Japan TLUG Members Links