next up previous 211
Next: Enlarging integer type in Fortran 77
Up: Modifications to code
Previous: Modifications to code

Pointer references in Fortran 77

As explained in SUN/209, whenever the %VAL Fortran compiler directive is used to pass the value of registered allocated memory to a subroutine, its argument should be wrapped in a call to CNF_PVAL. This effectively allows a 32-bit integer to address memory in a 64-bit address space. This call could in principle be avoided when long integers are being used in Fortran but it is still necessary where Fortran is written using normal integers in a 64-bit environment, so these calls must be incorporated. Since this change is less problematic than the move to large integers and is mostly independent of it, it is possible and advisable to make this change to all code and test it before converting the normal integer types as described in section 3.2.

As well as the calls to CNF_PVAL themselves, the header file CNF_PAR needs to be included in affected source files to provide the declaration of the CNF_PVAL function.

The main pitfall of making these modifications is wrapping the argument of a %VAL in a CNF_PVAL call when it ought not to be so wrapped. CNF_PVAL should only be applied to registered pointers. If your Fortran code uses pointers which are got from C without being registered with CNF, you'll need to address this in the C code as described in SUN/209. More commonly, you may have %VAL invocations which are not applied to pointers at all -- for instance when passing the lengths of character variables as trailing arguments which sometimes needs to be done when the compiler doesn't know that it's passing a character variable. In this case the %VAL invocation should be left alone and no call to CNF_PVAL inserted. In general, it is impossible to spot all such non-pointer uses of %VAL automatically. However, if %VAL is applied to a constant, or a small integer, then it should be left alone.

The program inscnf, and the corresponding driver script do-inscnf, is supplied for inserting CNF_PVALs in the right places. It wraps all arguments of %VAL in calls to CNF_PVAL, but emits warnings for those which look like they may not be pointers. It is described further in the appendix.



next up previous 211
Next: Enlarging integer type in Fortran 77
Up: Modifications to code
Previous: Modifications to code


Starlink System Note 73
Mark Taylor
13 August 2001
E-mail:ussc@star.rl.ac.uk

Copyright © 2001 Council for the Central Laboratory of the Research Councils