[J3] Specifying the PARAMETER and POINTER attributes on the same entity
Rafik Zurob
rzurob at ca.ibm.com
Thu Jul 18 21:29:20 EDT 2019
Thanks!
Rafik
"J3" <j3-bounces at mailman.j3-fortran.org> wrote on 18/07/2019 08:29:30 PM:
> From: Malcolm Cohen via J3 <j3 at mailman.j3-fortran.org>
> To: "'General J3 interest list'" <j3 at mailman.j3-fortran.org>
> Cc: Malcolm Cohen <malcolm at nag-j.co.jp>
> Date: 18/07/2019 08:29 PM
> Subject: [EXTERNAL] Re: [J3] Specifying the PARAMETER and POINTER
> attributes on the same entity
> Sent by: "J3" <j3-bounces at mailman.j3-fortran.org>
>
> 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 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.
More information about the J3
mailing list