[comp.lang.c] Interfacing FORTRAN with C

singh@unc.cs.unc.edu (Raj Kumar Singh) (12/20/88)

I think this question has been brought up before and so
I would like to exchange info with some one who can provide
helpful pointers on the issue of interprocedure calls between
C program and FORTRAN routines.

The specifics are as follows:

System: VaxStation-3200 running Ultrix-2.1.  


C-program {tt.c}
*******************************
#include <stdio.h>

main()
{
    extern void hello_();

    hello_();
}
*******************************

FORTRAN routine {hello.f}
*******************************

	subroutine hello()
	print *, "Hello world"
	return
	end
*******************************


This compiles without error on a Vaxes but on execution
does not print the message "hello world".  On the other hand,
the same program when compiled and run on Sun-3s and 4s works
fine.  Can someone provide more insight into this problem?
Is there anything special that I need to do on Ultrix system
in terms of loading?

Any help will be much appreciated.

Thanx !!!

------------------------------------------------------------
Raj Kumar Singh		singh@cs.unc.edu	(919) 962-1744

ir10@sdcc6.ucsd.EDU (Donald R. Fredkin) (12/22/88)

In article <5962@thorin.cs.unc.edu> singh@unc.cs.unc.edu (Raj Kumar Singh) writes:
>
>I think this question has been brought up before and so
>I would like to exchange info with some one who can provide
>helpful pointers on the issue of interprocedure calls between
>C program and FORTRAN routines.
>
>The specifics are as follows:
>
>System: VaxStation-3200 running Ultrix-2.1.  
>
>
>C-program {tt.c}
The following version works fine on a VaxStation-II running some flavor
or other of Ultrix.:
*******************************
#include <stdio.h>

extern void f_init(), f_exit(); /* fiddle with the Fortran I/O system */

MAIN_() /* f77 really wants this */
{
}

main()
{
	extern void hello_();

	f_init();
	hello_();
	f_exit();
	exit(0);
}
*******************************
>
>FORTRAN routine {hello.f}
unchanged.

I compile and link with the f77 command, which automatially includes
the right things from /usr/lib.
-- 

UUCP		{ihnp4,decvax!ucbvax,dcdwest,ucbvax}!ucsd.edu!drfredkin
Internet	drfredkin@ucsd.edu or drf%sdph2@ucsd.edu
Bitnet		drfredkin@ucsd

smryan@garth.UUCP (Xxxxxx Xxxx) (12/22/88)

I don't know about Ultrix, but as a general principle, never use
Fortran IO unless you begin with a Fortran Program. All systems
I have seen use the main entry point to initialise the runtime system,
including IO.
-- 
The maggot spawn of Ymir's flesh                                     -- s m ryan
whose lust of gold is trapping mesh,                            
have lost their hoard to gods and men,                          -- Andwari's Gem
now hid in river, mine, or fen.                                           -- 1/1