[J3] Specifying the PARAMETER and POINTER attributes on the same entity
Malcolm Cohen
malcolm at nag-j.co.jp
Thu Jul 18 20:29:30 EDT 2019
A1.
“The PARAMETER attribute specifies that an entity is a named constant. The entity has the value specified by its constant-expr,”
The BNF constant-expr only appears in the initialisation with “=”, i.e. the constraint
“C811 (R803) … If = appears in initialization, the entity shall not have the POINTER attribute.”
applies, which makes it a non-pointer.
QED.
Pointers can of course be constant. For example, a pointer component of a derived-type PARAMETER will be constant. Not to mention NULL(P) where P is a pointer that does not have non-constant length type parameters.
A2.
Since PARAMETER and POINTER are incompatible here, the question is moot.
Cheers,
--
..............Malcolm Cohen, NAG Oxford/Tokyo.
From: J3 <j3-bounces at mailman.j3-fortran.org> On Behalf Of Rafik Zurob via J3
Sent: Friday, July 19, 2019 7:48 AM
To: J3 Fortran <j3 at j3-fortran.org>
Cc: Rafik Zurob <rzurob at ca.ibm.com>
Subject: [J3] Specifying the PARAMETER and POINTER attributes on the same entity
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
Disclaimer
The Numerical Algorithms Group Ltd is a company registered in England and Wales with company number 1249803. The registered office is: Wilkinson House, Jordan Hill Road, Oxford OX2 8DR, United Kingdom. Please see our Privacy Notice <https://www.nag.co.uk/content/privacy-notice> for information on how we process personal data and for details of how to stop or limit communications from us.
This e-mail has been scanned for all viruses and malware, and may have been automatically archived by Mimecast Ltd, an innovator in Software as a Service (SaaS) for business.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.j3-fortran.org/pipermail/j3/attachments/20190719/cac9d7f3/attachment-0001.html>
More information about the J3
mailing list