CERN Accelerating science

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

next up previous
Next: Pointer arguments Up: Fortran 90 Tutorial: Previous: Association

Pointers in expressions and assignments

For intrinsic types we can ``sweep'' pointers over different sets of target data using the same code without any data movement. Given the matrix manipulation y = B C z, we can write the following code (although, in this case, the same result could be achieved more simply by other means):

      REAL, TARGET  :: b(10,10), c(10,10), r(10), s(10, z(10)
      REAL, POINTER :: a(:,:), x(:), y(:)
      INTEGER mult
      DO mult = 1, 2
         IF (mult == 1) THEN
            y => r              ! no data movement
            a => c
            x => z
            y => s              ! no data movement
            a => b
            x => r
         END IF
         y = MATMUL(a, x)       ! common calculation
      END DO
For objects of derived type we have to distinguish between pointer and normal assignment. In

      TYPE(entry), POINTER :: first, current
      first => current
the assignment causes first to point at current, whereas

      first =  current
causes current to overwrite first and is equivalent to

      first%value = current%value
      first%index = current%index
      first%next => current%next

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