Xref: utzoo comp.lang.fortran:823 comp.lang.c:10964
Path: utzoo!attcan!uunet!yale!husc6!cca!g-rh
From: g-rh@cca.CCA.COM (Richard Harter)
Newsgroups: comp.lang.fortran,comp.lang.c
Subject: Simulating Structures in Fortran
Message-ID: <30022@cca.CCA.COM>
Date: 28 Jun 88 13:44:16 GMT
References: <2742@utastro.UUCP> <20008@beta.UUCP> <224@raunvis.UUCP> <750@garth.UUCP> <528@philmds.UUCP> <817@garth.UUCP>
Reply-To: g-rh@CCA.CCA.COM.UUCP (Richard Harter)
Organization: Computer Corp. of America, Cambridge, MA
Lines: 42

In article <817@garth.UUCP> smryan@garth.UUCP (Steven Ryan) writes:

>>>Apparently some Fortran programmers equivalence different typed arrays to
>>>create structures (shudder).

>Some fortran programmers use the EQUIVALENCE statement to adjust the
>beginning address of different arrays with different types so that 
>they map their elements into interleaved storage. Don't know details--just
>heard about some of things they do just to stay in fortran. Like using
>blank common as a heap.

	It's been a long time since I've had to write fortran, and with 
luck it will be even longer as the years go by.  However I have used this
trick.  It runs like this:

C	Blank common is a heap; we assume that there is a storage allocator
C	returning an offset from blank common as an index.
C
	common heap
	integer heap(1)
	....
	equivalence (element1(1),heap(1))
	equivalence (element2(1),heap(2))
	equivalence (element3(1),heap(3))
	integer element1(1)
	integer element2(1)
	integer element3(1)
	....
C	Get a pointer to the structure from the allocator
C
	index = allocate(size)
	element1(index) = 0
	....
C	in general s->item is replaced by item(s_index)

	Isn't this fun.  Not as much fun, perhaps, as running red hot wires
under your fingernails, but fun.  
-- 

In the fields of Hell where the grass grows high
Are the graves of dreams allowed to die.
	Richard Harter, SMDS  Inc.