02.07.2013 Views

HP Fortran Programmer's Reference

HP Fortran Programmer's Reference

HP Fortran Programmer's Reference

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>HP</strong> <strong>Fortran</strong> statements<br />

EQUIVALENCE<br />

The <strong>Fortran</strong> 90 standard imposes the following type restrictions on equivalenced objects:<br />

320<br />

If one of the objects in equivalence-list is of type default integer, default real, double<br />

precision real, default complex, double complex, default logical, or numeric sequence type,<br />

then all objects in equivalence-list must be one of these types.<br />

<strong>HP</strong> <strong>Fortran</strong> relaxes this restriction and allows character and noncharacter items to be<br />

equivalenced. Note, however, that use of this extension can impact portability.<br />

If one of the objects in equivalence-list is of derived type that is not a numeric<br />

sequence or character sequence type, then all objects in equivalence-list must be of the<br />

same type.<br />

If one of the objects in equivalence-list is of intrinsic type other than default integer,<br />

default real, double precision real, default complex, double complex, default logical, or<br />

default character, then all objects in equivalence-list must be of the same type with<br />

the same kind type parameter value.<br />

<strong>HP</strong> <strong>Fortran</strong> relaxes this restriction.<br />

The EQUIVALENCE statement does not cause type conversion or imply mathematical<br />

equivalence. If an array and a scalar share the same storage space through the EQUIVALENCE<br />

statement, the array does not have the characteristics of a scalar and the scalar does not have<br />

the characteristics of an array. They only share the same storage space.<br />

Care should be taken when data types of different sizes share the same storage space, because<br />

the EQUIVALENCE statement specifies that each data item in equivalence-list has the same<br />

first storage unit. For example, if a 4-byte integer variable and a double-precision variable are<br />

equivalenced, the integer variable shares the same space as the 4 most significant bytes of the<br />

8-byte double-precision variable.<br />

Proper alignment of data types is always enforced. The compiler will issue a diagnostic if<br />

incorrect alignment is forced through an EQUIVALENCE statement. For data type alignment<br />

rules, see “Intrinsic data types” on page 25.<br />

The lengths of the equivalenced objects need not be the same.<br />

Equivalencing character data<br />

An EQUIVALENCE statement specifies that the storage sequences of character data items<br />

whosenamesarespecifiedinequivalence-list have the same first character storage unit.<br />

This causes the association of the data items in equivalence-list and can cause association<br />

of other data items as well. Consider the following example:<br />

CHARACTER(LEN=4) :: a, b<br />

CHARACTER(LEN=3) :: c(2)<br />

EQUIVALENCE (a, c(1)), (b, c(2))<br />

Chapter 10

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!