Simulating Structures in Fortran

Richard Harter g-rh at cca.CCA.COM
Tue Jun 28 23:44:16 AEST 1988


In article <817 at garth.UUCP> smryan at 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.



More information about the Comp.lang.c mailing list