🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: net.lang.f77
Article #355

Re: Query: Sharing f77 COMMONs with C Externals

#355
From: P.A.ul Layman [EE-Device Physics...
Date: Sat, 10 May 1986 01:34
55 lines
2527 bytes
In article <204@mdivax1.UUCP> kenward@mdivax1.UUCP (kenward) writes:
>By the way, the 4.2bsd convention appears to be that named commons have an 
>underscore appended to them, and may be so referenced from C.
>
>There is no mention that I can find on how to reference the fields of the 
>common block, that I can find.
>
Provided the common block is not blank common.  This refering to the
single common block available in f77 which does not have a name such as

	common //a,b,c,...

It is not a great problem. Merely extern the name of the common block
in your c program.  Just make sure you define it to be the same data type.
The following is a simple example which defines the elements of a real*4
common block in a fortran program then makes use of it in a c subroutine.

main program test.f
_____________________________________
	common /x/y
	real y(10)
	do 100 i=1,10
100	y(i)=i
	call comtst
	stop
	end
_____________________________________
subroutine comtst.c
_____________________________________
#include <stdio.h>
comtst_()
{
	extern float x_[];
	int i;
	for ( i=0 ; i<=9 ; i++ )
	    {
	    printf("x(%d) = %f\n",i,x_[i]);
	    }
	return(0);
}
_____________________________________
Note that the name used in the c routine is that of the "common block", x,
not that of the array used in the mainline, y, which is mapped into the
common block.  This name was only local to the mainline.  If you want
to use the same name in the c routine, you'll have to use pointers to elements
of the x_ array, but they won't have to have the "_" appended, because
they will again only be local.

I hope this helps.

PAul

P.S. it is sometime useful to use the -S option of f77 to look at
the assembler code of both the c program and the f77 program if you want
to see how they interact.
Technical Details
Message-ID: <2278@watdcsu.UUCP>
Path: arc1-ca.pugleaf.net!utzoo!watmath!watnot!watdcsu!sgcpal
References: <469@cubsvax.UUCP> <203@mdivax1.UUCP> <204@mdivax1.UUCP>

Show Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Posting-Version: version B 2.10.2 9/18/84; site watdcsu.UUCP
Path: arc1-ca.pugleaf.net!utzoo!watmath!watnot!watdcsu!sgcpal
From: sgcpal@watdcsu.UUCP (P.A.ul Layman [EE-Device Physics])
Newsgroups: net.lang.f77
Subject: Re: Query:  Sharing f77 COMMONs with C Externals
Message-ID: <2278@watdcsu.UUCP>
Date: Fri, 9-May-86 21:34:57 EDT
Article-I.D.: watdcsu.2278
Posted: Fri May  9 21:34:57 1986
Date-Received: Sat, 10-May-86 07:24:28 EDT
References: <469@cubsvax.UUCP> <203@mdivax1.UUCP> <204@mdivax1.UUCP>
Reply-To: sgcpal@watdcsu.UUCP (P.A.ul Layman [EE-Device Physics])
Organization: U of Waterloo, Ontario
Lines: 55
Keywords: example