<<To: ALEWIS%UTCVM.BITNET at cunyvm.cuny.edu

Root Boy Jim rbj at nav.icst.nbs.gov
Tue Jul 26 07:55:05 AEST 1988


Cc: unix-wizards at BRL.ARPA, BYKAT at utcvm.icst.nbs.gov
Subject: How FORTRAN allocates addresses for COMMON blocks?

? From: Adam Lewis <ALEWIS%UTCVM.BITNET at cunyvm.cuny.edu>

?  Suppose you have two COMMON blocks:

?                  COMMON /A/ IA(1)
?                  COMMON /B/ IAVAIL(99),LWRD

? and assume that you know that the COMMON blocks are allocated storage
? based upon lexographic order (this is the way that the FORTRAN
? compiler under VMS allocates storage for COMMON blocks).  As long as
? you take care not to place anything past the end of the /B/ COMMON
? block, you can run subscripts for the array IA from 1 to 100.
?     Does anybody out there have any idea how the different FORTRAN
? compilers for UNIX assign addresses to COMMON blocks?   It would seem
? to me that this kind of thing can differ greatly from compiler to
? compiler.   We have not yet been able to determine just how our
? compiler does this.  If anybody has some ideas, please drop a message
? and I'll summarize the results to the net.

This works on VMS because common blocks are put in .psects having the
same name as the common block. I have even seen such disgusting
practices as allowing the user to generate buffers in .psect IO$XXXX
and including .psect IO$XXXY that has a label defined in it. The size
of the buffer is computed at load time via the difference in labels.
The names have been changed to reflect my loss of memory.

In UNIX, the .comm directive is used to reserve space for all .bss
type things. You can think of a common block as really being a structure,
with the common block name being the real variable, and the FORTRAN
variables being member offsets.

It *may* be possible to get the common blocks loaded in the order you
want by defining that order explicitly in the main routine (read: first
object loaded), but I wouldn't bet on it, and would probably scream
epithets at the writer of such code. Don't try this one at home, kids!

It is possible that the loader and/or compiler might pad these areas
for alignment purposes as well.

I can't remember if it is possible to EQUIV things in different COMMON blocks,
but you might want to do that if it's legal.

	(Root Boy) Jim Cottrell	<rbj at icst-cmr.arpa>
	National Bureau of Standards
	Flamer's Hotline: (301) 975-5688
	The opinions expressed are solely my own
	and do not reflect NBS policy or agreement
	Careful with that VAX Eugene!



More information about the Comp.unix.wizards mailing list