CERN Accelerating science

This website is no longer maintained. Its content may be obsolete. Please visit for current CERN information.

next up previous
Next: Arrays of pointers Up: Fortran 90 Tutorial: Previous: Pointer arguments

Pointer functions

Function results may also have the POINTER attribute; this is useful if the result size depends on calculations performed in the function, as in

     USE data_handler
     REAL x(100)
     REAL, POINTER :: y(:)
     y => compact(x)
where the module data_handler contains

     FUNCTION compact(x)
        REAL, POINTER :: compact(:)
        REAL x(:)
  ! A procedure to remove duplicates from the array x
        INTEGER n
        :              ! Find the number of distinct values, n
        :              ! Copy the distinct values into compact
     END FUNCTION compact
The result can be used in an expression (but must be associated with a defined target).

Janne Saarela
Tue May 16 13:43:26 METDST 1995