Project 38: Pointers, dynamic storage management, list processing in Fortran Pasadena 1984: ============== (Feldmann): Any serious modern language needs a form of dynamic naming. If a heap mechanism is provides, as Fortran 8x now requires for arrays, pointer like type variables are essential. (Example : An interpreter system that allows a user to define arrays whose size changes dynamically). However, pointer usage can be dangerous, so the language should make it instantly clear when a pointer is being used, and when the object referenced is being used. Reid asks the group whether Fortran 8x should include pointers: the group is favorable by 16 yes, 0 no and 1 abstention. Como 1987: ========== Reid and Smith: It is expected that X3J3 will actively pursue a pointer facility in Fortran 8x. This interest in pointers arises from comments from users at forums and written comments to the committee. Proposals for pointers have been considered and reconsidered by X3J3 regularly since 1979. A pointer facility is a very difficult concept to introduce in Fortran 8X. The impact of pointers on the efficiency of both the compiler and runtime behaviour of a program can range from severe to acceptable depending upon the particular pointer facility. In addition, a pointer facility impacts a large number of features in the language, and since the contents of Fortran 8x have been in the state of flux, it has been difficult to prepare a complete proposal. Finally, there is a desire to add a pointer facility that represents an orthogonal facility in Fortran. As such, there is a requirement that several facilities, such as dynamic storage and aliasing, need to be modified considerably to be properly integrated with a pointer facility. The current plan is to seriously consider a pointer facility in the next several meetings prior to the public comment period. It is expected that the committee will receive requests for a pointer facility. Interest in a pointer facility in X3J3 has been a high as two to one but no cogent and complete proposal has been prepared to date. Stanford 1988: ============== The following is the summary of the report presented by B. Smith. A significant portion of the public review comments for FORTRAN 8X requested that a pointer facility be added to FORTRAN 8X. As a result of these comments, members of X3J3 have been preparing a pointer proposal that was presented at the last meeting, with comment text changes to the current draft FORTRAN 8X. The major characteristics of this proposal are: 1) A strongly-typed pointer facility is proposed. In contexts where strong typing is required, the requirement is that the pointer objects are in type and rank agreement. Such agreement is require in contexts such as operands of expressions (relaxed to matching of numeric types as in ordinary numeric expression in FORTRAN 77), argument association, and assignment statements. 2) Objects that are used in pointer contexts must be declared as pointers to targets, or both. The object pointed to by a pointer must be specified as a target. This requirement is made to aid optimization and safety of the code. 3) The use of a pointer variable in one expression, or as the "assigned-to" variable in an assignment statement, is an automatic dereference to object pointed to. The automatic dereference is one level at a time in the sense that pointers to pointers are not permitted directly. To obtain a pointer to a pointer, a structure type must be defined which contains a component of type pointer. A reference to such a component of an object that is itself a pointer will require two dereferences but such multiple dereferences are apparent from the syntactic form of the reference. 4) A new statement, called a pointer assignment statement, is proposed that allow the assignment of one pointer to another. 5) Objects, pointed to by a pointer, are allocated by and ALLOCATE statement. Objects that are explicitly allocated by an ALLOCATE statement can be deallocated by a DEALLOCATE statement. 6) A pointer can be declared as part of a structure. Recursive data structures are thus permitted, thereby using the pointer facility to create linked lists or trees of unspecified length. The following examples using recursive data definitions illustrate the above points. type CELL ! Define a "recursive" type integer VAL type (CELL), pointer :: NEXTCELL end type CELL type (CELL), target :: HEAD type (CELL), pointer :: CURRENT, TEMP ! declare pointers integer IOEM, K HEAD % VAL = 0 CURRENT => HEAD ! CURRENT points to head of list do read(*,*, iostat = IOEM) k ! read next value if any if(IOEM .ne. 0) exit allocate (TEMP) ! create new cell for each iteration TEMP%VAL=K ! assign value to cell CURRENT % NEXTCELL => TEMP ! attach new cell to list CURRENT => TEMP ! current points to new end of list end do A list is now constructed and the last linked cell contains a disassociated pointer. A loop can be used to "walk-through" the list CURRENT => HEAD do write(*,*) CURRENT%VAL if(.not. associated(CURRENT%NEXTCELL)) exit CURRENT => CURRENT % NEXTCELL end do Project [38], was merged with Project [20], FORTRAN 8X.