a1
and a2
in an equivalence
statement means that those two variables will occupy the same storage. Changing one will alter the other, even if they are variables of different types (e.g., a1
is an integer and a2
is a real.). Fortran doesn't give you any way to specify that a variable should be in a register and it seems extremely likely that an equivalence
statement will inhibit the compiler doing so automatically.
So
You could keep a1 in the memory location and keep a2 in a register for the whole of the procedure and this will be fine right?
is inapplicable.
I strongly recommend against the use of equivalence
... it is pernicious and likely only retained in the language to support legacy code. If you have the need to transfer data across types, the modern Fortran method is the transfer
intrinsic.