Usenet comp.unix.osf.osf1 (1992-2004)
 help / color / mirror / Atom feed
From: fuhrmann@weyl.wias-berlin.de (Juergen Fuhrmann)
Subject: Re: passing between C and Fortran
Date: 1995/11/15	[thread overview]
Message-ID: <FUHRMANN.95Nov15135026@weyl.wias-berlin.de> (raw)
In-Reply-To: 48aa3t$9im@news.cea.fr


>Hi,
>I have a C program calling Fortran functions, and inside the Fortran,
>i need to call some C functions.
>My programs comes from HPUX and i have to compile it on OSF1.
>But the f77 compiler isn't very happy with my source file..
>any help ?

Try this:
>>> file main.c <<<

#define essaifort essaifort_

main()
{
   essaifort();
}

>>> file fortran.F <<<

      integer function essaifort()
      integer ii=123

      call recupfort(ii)
      return
      end

>>> file c2.c <<<
#include <stdio.h>
#define recupfort recupfort_
void recupfort(ic)
int *ic;
{
    printf(" ic arg = %d\n",ic);
}


IMHO this should work under most unix systems. If not, the
Fortran compiler generates the external symbols in a different
way, and one should change the #define statements.

The rule is that fortran passes everything by reference,
so in C you should receive or pass pointers. You should
assure that int* goes to integer*4, double* to REAL*8 etc.

Character strings are a (very) different story.

Juergen


--
   Juergen Fuhrmann                          fuhrmann@wias-berlin.de
   Weierstrass Institute for Applied Analysis and Stochastics (WIAS)  
   Mohrenstrasse          39                 D-10117 Berlin, Germany     
   phone: (49) 030 20377 560                 fax:   (49) 030 2044975   
                                          
                    *  Bad News is No News *
                   
                   






  reply	other threads:[~1995-11-15  5:00 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1995-11-14  5:00 passing between C and Fortran francois CARTIER
1995-11-15  5:00 ` Juergen Fuhrmann [this message]
1995-11-16  5:00 ` Steve Lionel
1995-11-16  5:00 ` Shlenov Svyatoslav
read-only archive

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox