[J3] Specifying the PARAMETER and POINTER attributes on the same entity
Rafik Zurob
rzurob at ca.ibm.com
Thu Jul 18 18:48:29 EDT 2019
Hello
I have a couple of questions on specifying the PARAMETER and POINTER
attributes on the same entity.
Question 1. Is it valid to specify both the PARAMETER and POINTER
attributes on the same entity?
For example, is the following program valid?
integer, target, save :: t
integer, pointer, parameter :: p1 => t ! initial-data-target
integer, pointer, parameter :: p2 => null() ! null-init
end
As far as I can tell, the constraints forbidding mixing PARAMETER with
POINTER were removed starting in Fortran 2008.
Fortran 95 section 5.2.7 (POINTER statement) had:
Constraint: The PARAMETER attribute shall not be specified for an
object-name.
Fortran 2003 similarly had:
C514 (R501) The PARAMETER attribute shall not be specified for a dummy
argument, a pointer, an allocatable entity, a function, or an object in a
common block.
I can't find a similar constraint in Fortran 2008 or 2018. I also looked
into whether pointers had to be variables, and they don't appear to have
to be:
In Fortran 2008, 1.3.111 defines pointer as:
data pointer (1.3) or procedure pointer (1.3)
and then 1.3.111.1 defines data pointer as:
data entity with the POINTER attribute (5.3.14)
1.3.46 then says that data entity is:
data object, result of the evaluation of an expression, or the result of
the execution of a function reference
which already gets us away from variable. Section 1.3.47 says that data
object is:
constant (4.1.3), variable (6), or subobject of a constant (2.4.3.2.3)
I also couldn't find other references in the text requiring pointers to be
variables. The closest I found is the following in F2018:
7.5.4.6 Default initialization for components
2 A pointer variable or component is data-pointer-initialization
compatible with a target if the pointer is type
compatible with the target, they have the same rank, all nondeferred type
parameters of the pointer have the
same values as the corresponding type parameters of the target, and the
target is contiguous if the pointer has
the CONTIGUOUS attribute.
So, are pointers allowed to be parameters? (I don't think it's a very
useful thing to have and it would make it difficult to use techniques that
materialize the parameter's value when needed instead of allocating real
space for it. Now we either need to materialize a pointer descriptor on
the fly or allocate space for the parameter.) I also tried 3 compilers
and none accepted p1 or p2 above.
Question 2: Assuming that the answer to question 1 is that POINTER and
PARAMETER are allowed on the same entity, is it intentional that data
pointer initialization is forbidden in the PARAMETER statement? The
parameter statement's syntax only allows the equal sign and requires
constant-expr.
e.g.
integer, target, save :: t
integer, pointer :: p
parameter (p = t)
end
where the syntax is:
R551 parameter-stmt is PARAMETER ( named-constant-def -list )
R552 named-constant-def is named-constant = constant-expr
Thanks
Rafik
More information about the J3
mailing list