* passing between C and Fortran
@ 1995-11-14 5:00 francois CARTIER
1995-11-15 5:00 ` Juergen Fuhrmann
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: francois CARTIER @ 1995-11-14 5:00 UTC (permalink / raw)
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 ?
>>> file main.c <<<
main()
{
essaifort();
}
>>> file fortran.F <<<
$ALIAS recupfort='recupfort'(%val)
integer function essaifort()
integer ii=123
call recupfort(ii)
return
end
>>> file c2.c <<<
#include <stdio.h>
void recupfort(ic)
int *ic;
{
printf(" ic arg = %d\n",ic);
}
And the compiler response is...
$ALIAS recupfort='recupfort'(%val)
^
fort: Severe: argFort.F, line 1: Missing operator or delimiter symbol
I wonder that my $ALIAS is not known by OSF1, but what else ?
Any help will be appreciated
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Francois CARTIER | /| |~) /~\ |~) /| ~|~ /~\ | |~) |_~
cartier@lcus15.saclay.cea.fr |__/~| |_) \_/ |~\ /~| | \_/ | |~\ |__
CEA - CEREM |~\ |_~ /~` /~\ |\| ~|~ |~) /~\ | |_~ |~) /| |~)
Service des |_/ |__ \_, \_/ | | | |~\ \_/ |__ |__ | /~| |~\
Techniques Avancees
LCUS | | | ~|~ |~) /| (~ /~\ |\| (~
91191 Gif sur Yvette FRANCE |_| |__ | |~\ /~| _) \_/ | | _)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: passing between C and Fortran
1995-11-14 5:00 passing between C and Fortran francois CARTIER
@ 1995-11-15 5:00 ` Juergen Fuhrmann
1995-11-16 5:00 ` Steve Lionel
1995-11-16 5:00 ` Shlenov Svyatoslav
2 siblings, 0 replies; 4+ messages in thread
From: Juergen Fuhrmann @ 1995-11-15 5:00 UTC (permalink / raw)
>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 *
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: passing between C and Fortran
1995-11-14 5:00 passing between C and Fortran francois CARTIER
1995-11-15 5:00 ` Juergen Fuhrmann
@ 1995-11-16 5:00 ` Steve Lionel
1995-11-16 5:00 ` Shlenov Svyatoslav
2 siblings, 0 replies; 4+ messages in thread
From: Steve Lionel @ 1995-11-16 5:00 UTC (permalink / raw)
In article <48aa3t$9im@news.cea.fr>, francois CARTIER
<cartier@lcus15.saclay.cea.fr> writes:
|>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 ?
In the current (V3.8) release of DEC Fortran, there's the CDEC$ ALIAS
directive which is similar to the $ALIAS directive in HP's Fortran, though
it specifies the name alias only, not the passing mechanism. Your Fortran
code would look like this:
CDEC$ ALIAS recupfort,'recupfort'
integer function essaifort()
integer ii=123
call recupfort(%val(ii))
return
end
The next version of Digital Fortran will include a new directive that will give
you the ability to say "this is the name of a C routine" and it will apply
C naming and passing-mechanism semantics automatically.
--
Steve Lionel Mail: lionel@quark.enet.dec.com
DEC Fortran Development WWW: http://www.digital.com/info/slionel.html
Digital Equipment Corporation CompuServe: 75263,3001
110 Spit Brook Road, ZKO2-3/N30
Nashua, NH 03062-2698 "Free advice is worth every cent"
For information on DEC Fortran 90, see http://www.digital.com/info/hpc/f90/
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: passing between C and Fortran
1995-11-14 5:00 passing between C and Fortran francois CARTIER
1995-11-15 5:00 ` Juergen Fuhrmann
1995-11-16 5:00 ` Steve Lionel
@ 1995-11-16 5:00 ` Shlenov Svyatoslav
2 siblings, 0 replies; 4+ messages in thread
From: Shlenov Svyatoslav @ 1995-11-16 5:00 UTC (permalink / raw)
>... and inside the Fortran,
>i need to call some C functions.
>
>>>> file c2.c <<<
>void recupfort(ic)
Instead of using
>$ALIAS recupfort='recupfort'(%val)
in the Fortran program
you may name the C-program like
void recupfort_(int* ic)
and call it from inside Fortran as
call recuport(ic) (without _ )
but of course the C-program in this case should deal with pointers.
S. Shlenov.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~1995-11-16 5:00 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1995-11-14 5:00 passing between C and Fortran francois CARTIER
1995-11-15 5:00 ` Juergen Fuhrmann
1995-11-16 5:00 ` Steve Lionel
1995-11-16 5:00 ` Shlenov Svyatoslav
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox