To: J3 J3/23-198 From: Malcolm Cohen Subject: Readonly pointers Date: 2023-June-14 1. Introduction Sometimes it is useful to have a pointer to data, where the pointer itself cannot be used to modify that data. That enables safe usage of INTENT(IN) TARGET dummy arguments, for example. This is such a proposal. 2. Proposal That a new attribute be applicable to pointers that determines whether the target of the pointer cannot be changed through the pointer. The default would remain that the target can be changed. Note: It is already possible to have a pointer to a target that is not allowed to be changed, e.g. PROTECTED, INTENT(IN), or a dummy with an actual argument that is an expression. For backwards compatibility, this situation will not be changed (though it is perhaps possible that *some* cases could be made obsolescent in the future). 3. Illustrative syntax REAL,POINTER,READONLY :: p Constraint: A READONLY pointer shall not appear in a variable definition context. Constraint: A READONLY pointer shall not be pointer-assigned to a pointer that does not have the READONLY attribute. etc. A READONLY pointer may, unless otherwise prohibited, appear in a pointer association context, e.g. ALLOCATE(p,SOURCE=1.5) ! Can never be changed after this. p => target NULLIFY(p) but not in a DEALLOCATE statement, viz DEALLOCATE(p) makes the target go undefined, so is definitely prohibited. READONLY is not a particularly good keyword, but is perhaps acceptable if we cannot reach agreement on a better one. Suggested alternatives so far include IMMUTABLE INDEFINABLE UNASSIGNABLE Subgroup slightly favours IMMUTABLE, but declines to make a decision yet. ===END===