[comp.lang.c] Simulating Structures in Fortran

g-rh@cca.CCA.COM (Richard Harter) (06/28/88)

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.