[comp.lang.fortran] How do compilers handle dimensions?

FC138001@ysub.ysu.edu (Phil Munro) (07/17/90)

  All of my Fortran has been with mainframes and for the past year or
so I am using the VS2 compiler.  Probably my questions are simple, but
perhaps they will be of interest to others also.

1. The normal dimension byte size on the mainframe machine (which I
presume is a 64-bit machine) is *4.  Does this size, and the resulting
size of numbers, have anything to do with the bit size of a machine?
For example, a PC would have 8, 16, or 32 for the bit size depending
upon whether it is an XT-type, AT-type, or 386-type machine, as I
understand it.  If I transport a program from a 64-bit mainframe, will
the numerical precision for REAL numbers, and the maximum size for
INTEGERS, be less?  Would it be necessary to change variables to
DOUBLE PRECISION, or something like that, to get the same precision?

2. Are the dimension statements REAL*8, etc., part of Fortran 77, 90
or whatever, or are they just a VS extension?

  Thanks for any discussion on these things.  --Phil

jerry@heyman.austin.ibm.com (Jerrold Heyman) (07/18/90)

In article <90198.114258FC138001@ysub.ysu.edu> FC138001@ysub.ysu.edu (Phil Munro) writes:
>
>  All of my Fortran has been with mainframes and for the past year or
>so I am using the VS2 compiler.  Probably my questions are simple, but
>perhaps they will be of interest to others also.
>
>1. The normal dimension byte size on the mainframe machine (which I
>presume is a 64-bit machine) is *4.  Does this size, and the resulting
>size of numbers, have anything to do with the bit size of a machine?
>For example, a PC would have 8, 16, or 32 for the bit size depending
>upon whether it is an XT-type, AT-type, or 386-type machine, as I
>understand it.  If I transport a program from a 64-bit mainframe, will
>the numerical precision for REAL numbers, and the maximum size for
>INTEGERS, be less?  Would it be necessary to change variables to
>DOUBLE PRECISION, or something like that, to get the same precision?
>
Most mainframes that I've come in contact with use a 32-bit WORD.  I'm aware
of Cray's 64-bit word and probably there exist a few others, but making the
assumption of a 64-bit word might be incorrect.

As for the rest of your question, several years ago I ported a Fortran 77 
program from a PRIME 750 to an IBM PC Clone (using Microsoft Fortran 3.2).
With the exception of things that the Microsoft compiler didn't support (mostly
string handling), we used the code as is and came up with the same results as
the PRIME.  Now I know that the PRIME is a 32-bit machine, and the PC Clone
was an Intel 8088 based machine (making it an 8/16 bit machine).  The only big
thing that was noticed with the word size was that INTEGERS on the Clone
defaulted to 16-bit and therefore any number larger than 2^16-1 would cause
overflow.  This was compensated by declaring all variables INTEGER*4 (forcing
them to be 32-bit) - can't remember if there was a compiler directive or not.

>2. Are the dimension statements REAL*8, etc., part of Fortran 77, 90
>or whatever, or are they just a VS extension?
>

REAL*8 is part of the Fortran 77 definition (its the same as DOUBLE PRECISION),
not sure about the Fortran 90 standard.

>  Thanks for any discussion on these things.  --Phil


--
Jerry Heyman              AWD Austin                            AIX Development
VNET: HEYMAN at AUSVMQ    IBM T-R: jerry@heyman.austin.ibm.com  T/L: 793-3962

seymour@milton.u.washington.edu (Richard Seymour) (07/18/90)

In article <90198.114258FC138001@ysub.ysu.edu> FC138001@ysub.ysu.edu (Phil Munro) writes:
>  All of my Fortran has been with mainframes and for the past year or
>so I am using the VS2 compiler.  Probably my questions are simple, but
>perhaps they will be of interest to others also.
>
>1. The normal dimension byte size on the mainframe machine (which I
>presume is a 64-bit machine) is *4. 
   i think you're misusing the word "dimension" -- what you appear to
    be asking is the size of a data item (or variable).
   Four bytes (32 bits) is what many systems have settled on because:
     IBM did first (before 1967, at least)
     16-bit and 32-bit computers handle it easily.
     Many pre-1978 systems (Data General for one) did not support
       integers greater than 16-bits.
> Does this size, and the resulting
>size of numbers, have anything to do with the bit size of a machine?
    i think you mean "word size" instead of "bit size"
   and the answer to that is "yes".  CDC (for example) has some
   60-bit machines, and all of their items were 60 bits (or controllable
   subsets thereof) long.  Hence you could have BIG integers, and
   lots of REAL precision.
>For example, a PC would have 8, 16, or 32 for the bit size depending
>upon whether it is an XT-type, AT-type, or 386-type machine, as I
>understand it.  If I transport a program from a 64-bit mainframe, will
>the numerical precision for REAL numbers, and the maximum size for
>INTEGERS, be less?  Would it be necessary to change variables to
>DOUBLE PRECISION, or something like that, to get the same precision?
   i think you'll find that most PC (all types) compilers use REAL*4
   as their default.  Whether you gain or lose a bit of precision
   depends up[on how the manufacturer chops the REAL data type into
   mantissa and exponent regions.
>
>2. Are the dimension statements REAL*8, etc., part of Fortran 77, 90
>or whatever, or are they just a VS extension?
     they are an extension (the ANSI standard doesn't show "*8")
     but many compiler suppiers support the syntax (again, IBM did
    it first, and everyone needed to be sort of compatible)
>
>  Thanks for any discussion on these things.  --Phil
    good luck
    --dick

khb@chiba.Eng.Sun.COM (Keith Bierman - SPD Advanced Languages) (07/18/90)

In article <90198.114258FC138001@ysub.ysu.edu> FC138001@ysub.ysu.edu (Phil Munro) writes:


   1. The normal dimension byte size on the mainframe machine (which I
   presume is a 64-bit machine) is *4.  Does this size, and the

byte = 8 bits
*4 means 4 bytes = 32 bits.

In days gone by, words were king, not bytes. X3.9-1978 talks about
storage units which are more like words than bytes.

By convention (but not any formal standard)

	real*4 means "single precision" aka real and generally 32-bit
	real*8 means "double precision" aka double precision and generally 64-bit

Since some machines (viz. cdc 6600 and its ilk) have 60-bit words,
real*4 means real (i.e. 60-bit) ... but for all byte oriented machines,
that I am aware of, real*4 gets you 32-bit quanties.



   2. Are the dimension statements REAL*8, etc., part of Fortran 77, 90
   or whatever, or are they just a VS extension?

I don't recall who introduced *n syntax first. It is commonly found
on:

	vms
	Sun
	Convex
	PC  (misc. compilers, lahey, ms, etc.)
	LPI (all platforms)
	DG
and many, many others.

cheers
--
Keith H. Bierman    |*My thoughts are my own. !! kbierman@Eng.Sun.COM
It's Not My Fault   | MTS --Only my work belongs to Sun* khb@chiba.Eng.Sun.COM
I Voted for Bill &  | Advanced Languages/Floating Point Group (415 336 2648)   
Opus<khb@eng.sun.com> "When the going gets Weird .. the Weird turn PRO"

levine@crimee.ics.uci.edu (David Levine) (07/18/90)

Jerrold Heyman writes:

>Phil Munro writes:
>>2. Are the dimension statements REAL*8, etc., part of Fortran 77, 90
>>or whatever, or are they just a VS extension?
>>
>REAL*8 is part of the Fortran 77 definition (its the same as DOUBLE PRECISION),
>not sure about the Fortran 90 standard.

REAL*8 is a popular extension, but it is not standard Fortran 77
or Fortran 90.  DOUBLE PRECISION is often the same as REAL*8, but
not always:  the only requirement is that it provide more precision
than REAL.

David L. Levine, Dept. of ICS             Internet: levine@ics.uci.edu
University of California, Irvine                BITNET: levine@ucivmsa
Irvine, CA 92717                            UUCP: ucbvax!ucivax!levine

jlg@lanl.gov (Jim Giles) (07/19/90)

From article <KHB.90Jul17133126@chiba.Eng.Sun.COM>, by khb@chiba.Eng.Sun.COM (Keith Bierman - SPD Advanced Languages):
> [...]
> Since some machines (viz. cdc 6600 and its ilk) have 60-bit words,
> real*4 means real (i.e. 60-bit) ... but for all byte oriented machines,
> that I am aware of, real*4 gets you 32-bit quanties.

I used to use the 6600 all the time and I don't remember that it even
_had_ a REAL*4 (or star anything) declarator.  If it _did_, I would have
expected it to mean a 4-byte real like on other machines.  In the case
of the 6600, this would mean a 24-bit real (4 bytes at 6-bits per byte).
Mind you, an INTEGER*8 would have made sense in this scheme - it would
have corresponded to a 48-bit integer which was the most efficient size
of integer on the machine.

J. Giles