This website is no longer maintained. Its content may be obsolete. Please visit http://home.cern/ for current CERN information.
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 ELSE y => s ! no data movement a => b x => r END IF y = MATMUL(a, x) ! common calculation END DOFor objects of derived type we have to distinguish between pointer and normal assignment. In
TYPE(entry), POINTER :: first, current : first => currentthe assignment causes first to point at current, whereas
first = currentcauses current to overwrite first and is equivalent to
first%value = current%value first%index = current%index first%next => current%next