[comp.lang.c] How do I access f77 common variables from C ?

peter@maccs.McMaster.CA (peter) (07/20/88)

How does one access common variables (in blank or named common block) from
a C function linked to an f77 program ?

-- 
Todd Pfaff, PFAFF@MCMASTER.BITNET, peter@maccs.UUCP

karish@denali.stanford.edu (Chuck Karish) (07/20/88)

In article <1324@maccs.McMaster.CA> peter@maccs.UUCP (peter) writes:
>How does one access common variables (in blank or named common block) from
>a C function linked to an f77 program ?

	I've done this (pcc, f77) by declaring an external structure
	in the C program with the same name as the common block.
	The obvious pitfall in this is that you assume that the
	alignment and data representation in the structure are
	the same as in the common block.  If there is a difference,
	it may be necessary to insert dummy variables into one or
	the other to make things fit.

	For blank common, individual external variables should work;
	I haven't tried this, though.

Chuck Karish	ARPA:	karish@denali.stanford.edu
		BITNET:	karish%denali@forsythe.stanford.edu
		UUCP:	{decvax,hplabs!hpda}!mindcrf!karish
		USPS:	1825 California St. #5   Mountain View, CA 94041

jdp@adiron.UUCP (Powell) (07/28/88)

On some systems, the global structure works (Berkeley).

On at least SILICON GRAPHICS, a structure has to be defined in C
and the common block in Fortran and a subroutine accepting a pointer
to the first type in the common area has to be written in Fortran
and called by C with the pointer to the structure.  In addition,
a bridge routine has to be created in order to call Fortran from C.

Good Luck.

					jdp