A little pointer on POINTER in data would be helpful
Tim Zeisloft
tim@marlettesoftware.com
Sat Mar 24 20:08:00 GMT 2018
On 3/24/2018 2:35 AM, fortran-digest-help@gcc.gnu.org wrote:
> looking at the various versions of the program, I wonder if the data
> statement is supposed to work as an association. Normally one does:
>
> p => target_variable
> p = 1
>
> or the like, so first an explicit association via => (or an
> allocation) and then the assignment. A data statement simply assigns
> the values and can not refer to variables. Hence it seems unlikely
> that any of the above programs is standard conforming. With the
> possible exception of "data p / null() /".
I agree with Arjen that the data statement is restricted to assignment
only, and does not allow or assume pointer assignment. If one accepts
that the statement "data idata/1/" is the equivalent of "integer ::
idata=1" then R505 dictates that the component initialization must be a
constant expression, so the compiler reaction appears correct. It seems
that C510 might also have something to say about the situation.
The result of the null() function is considered to be a data constant
(R542), and the standard specifically describes it's use in a data
statement in table 13.2. Another subtlety is that the appearance of the
variable in the data statement results in rules for explicit
initialization to override the rules for default initialization. One
implication of this is that the object is automatically granted the save
attribute when explicitly initialized while it is not when default
initialization is used.
> If data-stmt-constant is initial-data-target the corresponding
> data statement object shall be data-pointer-initialization
> compatible with the initial data target; the data statement
> object is initially associated with the target.
>
> This is where it gets interesting.
>
> R443 initial-data-target is designator
> R601 designator is object-name
> or array-element
> or array-section
> or coindexed-named-object
> or complex-part-designator
> or structure-component
> or substring
>
> After bouncing around abit, one finds
>
> C766 A designator that is an initial-data-target shall designate
> a nonallocatable, noncoindexed variable that has the TARGET and
> SAVE attributes and does not have a vector subscript. Every
> subscript, section subscript, substring starting point, and
> substring ending point in designator shall be a constant expression.
>
> program p
> integer, target, save :: m = 3
> type t
> integer, pointer :: n
> end type
> type(t) :: z
> data z%n / m /
> m = 3
> print *, z%n
> end
>
> % gfcx -o z b.f90
> b.f90:7:15:
>
> data z%n / m /
> 1
> Error: Symbol 'm' must be a PARAMETER in DATA statement at (1)
>
> Whoops.
The rule R443 appears in the context of default initialization, but we
are explicitly initializing because of the data statement, so R443
doesn't seem to apply.
If one looks at the definition of what can appear in a
data-stmt-value-list (5.4.7.6), everything must reduce to a constant
expression, which confirms that the compiler is correctly diagnosing the
situation.
Tim
More information about the Fortran
mailing list