12-106
To: J3
From: Van Snyder
Subject: Interpretation concerning constant expressions and pointers
Date: 2012 January 19
----------------------------------------------------------------------
NUMBER: F08/xxxx
TITLE: Are certain expressions with pointer initialization constant?
KEYWORDS: constant, pointer initialization
DEFECT TYPE: Erratum
STATUS: Under J3 consideration
QUESTION:
Given
program P
type :: T
character(len=:), pointer :: P
end type T
character(len=10), target, save :: V = 'Value of V'
real :: R
1 type(t), parameter :: Z = t(v)
2 type(t), parameter :: X = transfer(sqrt(transfer(z,r)),z)
3 v = 'New Value'
4 z%p = 'New Value'
contains
subroutine S
5 character(len=*), parameter :: Y = z%p
...
(1)
are the initialization expressions in statements 1 and 2 constants?
(2)
are the assignments in statements 3 and 4 permitted?
(3)
is the initialization expression in statement 5 a constant?
ANSWER:
(1)
According to 7.1.12p1(3)(b), the initialization expressions in
statements 1 and 2 are constants. Nonetheless, a processor cannot
evaluate the expression in statement 2 as a constant. Edits are
provided to correct this oversight.
(2)
The assignment in statement 3 is permitted, but the one in statement 4
is not, because z%p is a subobject of a constant, and therefore is a
constant. No edits are required.
(3)
According to 7.1.12p1(1) the initialization expression in statement 5
is a constant. Nonetheless, although the pointer association status of
a subcomponent of an object is a constant, its target, if it has one, is
not a constant. An edit is provided to correct this oversight.
EDITS:
(3)
In 7.1.12p1(1) insert "nonpointer" before "subobject".
(1)
In 7.1.12p1(6) insert ", or TRANSFER" after "THIS_IMAGE"
Insert a list item after 7.1.12p1(6)
"(6a) A reference to the intrinsic function TRANSFER, where each
argument is a constant expression that does not have a pointer
ultimate component,"
SUBMITTED BY: Van Snyder
HISTORY: 12-xxx m197 F08/xxxx submitted