[comp.lang.fortran] More on EQUIVALENCE

Phil Munro <FC138001@ysub.ysu.edu> (06/08/91)

>     ...                                               It has struck me
>since however that since the standard doesn't say what to do when one
>equivalences across data types, a particularly odd compiler could
>transform the "obvious" meaning of EQUIVALENCE into something else
>entirely (and still conform to the standard).  (I believe that this
>situation is common when equivalencing any numerical type to CHARACTER
>because of the peculiar way in which character variables are stored in
>some systems.)  I therefore retract my example.  I don't think you can use
>equivalence portably to do anything other than save space.
>
>                                Marc R. Roussel
>                                mroussel@alchemy.chem.utoronto.ca

  The above discussion raises questions for me.  Will the following code
be portable?  Might it cause problems on some compilers when trying to
pick off part of whole and overlay storage?  I know in the case of the
VS compiler that character storage allows this sort of thing.

      character*14 whole
      character*4  part
      data whole /'part and so on'/
      equivalence (whole,part)

  Or, here is another simpler example which I have used:

      character*8 blank8
      character*4 blank
      equivalence (blank8,blank)
      data blank8 /' '/

orville@weyrich.UUCP (Orville R. Weyrich) (06/09/91)

In article <91159.121142FC138001@ysub.ysu.edu> Phil Munro <FC138001@ysub.ysu.edu> writes:
>
>  The above discussion raises questions for me.  Will the following code
>be portable?  Might it cause problems on some compilers when trying to
>pick off part of whole and overlay storage?  I know in the case of the
>VS compiler that character storage allows this sort of thing.
>
>      character*14 whole
>      character*4  part
>      data whole /'part and so on'/
>      equivalence (whole,part)
>

The first release of the IBM FORTRAN-VS compiler was [I think] standard-
conforming in the way it treated character strings, but it broke a lot of
code written for other compilers [E.g. WATFIV].  IBM made some major
changes in the way FORTRAN-VS handled characters in their next release.

I don't recall the details. I am sure that parameter-passing was one of the
problems. I am not sure about other forms of storage association.


--------------------------------------           ******************************
Orville R. Weyrich, Jr., Ph.D.                   Certified Systems Professional
Internet: orville%weyrich@uunet.uu.net             Weyrich Computer Consulting
Voice:    (602) 391-0821                         POB 5782, Scottsdale, AZ 85261
Fax:      (602) 391-0023                              (Yes! I'm available)
--------------------------------------           ******************************

bill@hcx2.ssd.csd.harris.com (Bill Leonard) (06/10/91)

In article <91159.121142FC138001@ysub.ysu.edu>, FC138001@ysub.ysu.edu (Phil Munro) writes:
>   The above discussion raises questions for me.  Will the following code
> be portable?  Might it cause problems on some compilers when trying to
> pick off part of whole and overlay storage?  I know in the case of the
> VS compiler that character storage allows this sort of thing.
> 
>       character*14 whole
>       character*4  part
>       data whole /'part and so on'/
>       equivalence (whole,part)
> 
>   Or, here is another simpler example which I have used:
> 
>       character*8 blank8
>       character*4 blank
>       equivalence (blank8,blank)
>       data blank8 /' '/

Both examples are standard conforming.  EQUIVALENCE between two CHARACTER
entities is defined by the standard.  What the standard _disallows_ is
EQUIVALENCE between CHARACTER and other data types.

-- 
Bill Leonard
Harris Computer Systems Division
2101 W. Cypress Creek Road
Fort Lauderdale, FL  33309
bill@ssd.csd.harris.com
---------------------------------------------------------------------------
"Chronologically gifted" -- new government term for "old".  Does this make
babies "chronologically deprived"?
---------------------------------------------------------------------------

pa@curly.appmag.com (Pierre Asselin) (06/11/91)

In article <91159.121142FC138001@ysub.ysu.edu> FC138001@ysub.ysu.edu (Phil Munro) writes:
>[...]
>  The above discussion raises questions for me.  Will the following code
>be portable?  Might it cause problems on some compilers when trying to
>pick off part of whole and overlay storage?  I know in the case of the
>VS compiler that character storage allows this sort of thing.
>
>      character*14 whole
>      character*4  part
>      data whole /'part and so on'/
>      equivalence (whole,part)
>
>  Or, here is another simpler example which I have used:
>
>      character*8 blank8
>      character*4 blank
>      equivalence (blank8,blank)
>      data blank8 /' '/

This is a quote from X3.9-1978 (section 8.2.3):
#   In the example:
#
#       CHARACTER A*4, B*4, C(2)*3
#       EQUIVALENCE (A(C(1)), (B,C(2))
#
#   The association of A, B, and C can be graphically illustrated as:
#
#       |01|02|03|04|05|06|07|
#       |-----A-----|
#                |-----B-----|
#       |--C(1)--|--C(2)--|

I don't want to quote the whole section, but the example shows that
your intuition is probably right.  The equivalences do not hold beyond
the declared bounds.  Do not assume, say, that A(5:5) exists and is
associated with B(2:2).

--Pierre Asselin, R&D, Applied Magnetics Corp.  I speak for me.