[comp.lang.fortran] pointers

ok@quintus.uucp (Richard A. O'Keefe) (09/25/88)

In article <4151@lanl.gov> jlg@lanl.gov (Jim Giles) writes:
[In reply to Peter da Silva, about pointers]
>From article <1584@ficc.uu.net>, by peter@ficc.uu.net (Peter da Silva):
>1) It rasies the spectre of aliasing in contexts where it doesn't exist
>   if the pointer isn't user accessible.  For this reason, things that
>   would otherwise vectorize or unroll for pipelining must be done by
>   the compiler as if the possible aliasing has actually occurred.

If we can widen the topic slightly to a consideration of pointers in
general (after all, why shouldn't Fortran 9X have *better* pointers
than C?), it may be of interest to note that

    Array subscripts pose *EXACTLY* the same aliasing problem in
    Fortran as pointers do in C.  The only standard-defined (and
    yes the standard is not yet official, but it's not likely to
    change much, and _this_ has been so since K&R 1st edition)
    ways for pointers p and q to point to the same object are for
    them to point to the same variable -- not a vectorising issue
    because in that case it doesn't make sense to do pointer
    arithmetic on them -- or to point to the same element of some
    array.

    The difference, then, between
    are ANARAY(I) and ANARAY(J) aliased?		(Fortran), and
    are *p and *q aliased?				(C)
    is that mention of the common array is suppressed in C.

But doesn't the fact that the array name has to be mentioned in Fortran
mean that the compiler can be sure that ANARAY(I) and ANOTHR(J) are not
aliased?  No, that _alone_ is not enough.  Consider this fragment:

	DIMENSION POOL(200)
	...
	CALL INPAIN(POOL(1), 150, POOL(100), 50)
	...
	SUBROUTINE INPAIN(ANARAY, I, ANOTHR, J)
	    INTEGER I, J
	    DIMENSION ANARAY(*), ANOTHR(*)
	    ...

Fortran had to be augmented with _additional_ rules about what aliasing
was legal in cases like this precisely because integer subscripts are
enough to cause aliasing problems even with different array names.  The
'noalias' keyword was an attempt to do the same to C.

What you need to know is that two pointers can't point to the same thing,
and various languages other than C have used 'zones', 'collections',
assertions, and other methods of achieving this end.