[comp.lang.fortran] Pointers in FORTRAN 8X

bobal@microsoft.UUCP (Bob Allison) (10/07/88)

I've decided to try to present the proposal going around X3J3 for pointers 
(which is in the language WG-5 is demanding, I believe).  Take this
for informational and discussion purposes only: I do not make any claims
as to the quality or lack of for this proposal.

There are two new attributes for types, POINTER and TARGET. You can 
allow a structure to have a field which is defined to be a pointer to the
structure (this allows linked lists).  You allocate objects via the
ALLOCATE statement.  The rules for the ALLOCATE statement were also 
changed so you could allocate a scalar with the POINTER attribute.
There is a new kind of assignment, pointer assignment, which copies
the address instead of the value, symbolized by "=>".  So, if you want
to copy the contents of one structure pointed to by "P" to another structure
pointed to by "Q", you write "P=Q"; if you want "P" to point to what "Q"
points to, you write "P=>Q".  Pointers can only point at variables with the
TARGET attribute, or objects which have been allocated.  There are a couple 
of intrinsics which will tell you whether a guy is pointing to something 
and whether one guy is specifically pointing at another guy.  Here's a 
program fragment which might give you a feel for how they work.

       TYPE cell                           ! this will be a linked list
          INTEGER            :: val
          TYPE(cell),POINTER :: nextcell
       END TYPE

       TYPE(cell),TARGET     :: head       ! a guy we can point to
       TYPE(cell),POINTER    :: current,temp  ! some pointers      
       INTEGER               :: ioem,k        ! God, I hate double colons

       head%val = 0
       current => head                    ! point to head of list
       DO
          READ (*,*,iostat=ioem),k
          IF (ioem.NE.0) EXIT
          ALLOCATE(temp)
          temp%val = k
          current%nextcell => temp
          current => temp
       END DO

If you want more details, I can provide them, but this is a general feel
for how pointers might work in 8X (if they are added to the language).

Bob Allison

ok@quintus.uucp (Richard A. O'Keefe) (10/07/88)

In article <3@microsoft.UUCP> bobal@microsoft.UUCP (Bob Allison (uunet!microsoft!bobal)) writes:
>I've decided to try to present the proposal going around X3J3 for pointers 
>(which is in the language WG-5 is demanding, I believe).

Thank you.

>So, if you want
>to copy the contents of one structure pointed to by "P" to another structure
>pointed to by "Q", you write "P=Q"; if you want "P" to point to what "Q"
>points to, you write "P=>Q".

Oh dear oh dear oh dear.  Simula 67 had the same idea (the operators were
:= and :-) but the thing which saved Simula was that for a given P and Q
only one of the operators was legal.  The difference between two statements
with such different effects should _not_ be a single character.  In C,
which I do not for a moment claim is ideal, the distance between the
statements is two characters:  *P = *Q; -vs- P = Q;  and in ADA the
difference is 8 characters:  P.all := Q.all;  -vs-   P := Q;
And then to make the operation look as though it assigns P to Q!

We've had enough discontent expressed in comp.lang.c with the fact
that mistyping P==Q (a comparison) may yield a valid expression P=Q
to indicate that single-character errors are alive and well (and of
course Bliss programmers know this to their cost).  When will we learn?