A little pointer on POINTER in data would be helpful

Steve Kargl sgk@troutmask.apl.washington.edu
Sat Mar 24 23:06:00 GMT 2018


On Sat, Mar 24, 2018 at 03:45:30PM -0700, Tim Zeisloft wrote:
> On 3/24/2018 1:51 PM, Steve Kargl wrote:
> >
> > A data-stmt-constant shall be null-init or initial-data-target if and
> > only if the corresponding data-stmt-object has the POINTER attribute.
> > If data-stmt-constant is null-init, the initial association status of
> > the corresponding data statement object is disassociated.  If
> > data-stmt-constant is initial-data-target the corresponding data statement
> > object shall be data-pointer-initialization compatible (7.5.4.6) with the
> > initial data target; the data statement object is initially associated
> > with the target.
> I would remark that my comments were based on the F2008 standard, as 
> that is what was cited in the original post. Nonetheless, what you post 
> looks similar.

I just checked F2003.  It only has

R532 data-stmt-constant  is scalar-constant
                         or scalar-constant-subobject
                         or signed-int-literal-constant
                         or signed-real-literal-constant
                         or null-init
                         or structure-constructor

So, initial-data-target was added in F2008. 

> > So, I believe the standard says the following code is conforming
> >
> > subroutine sub(i)
> >     integer, intent(in) :: i
> >     integer, save, target :: j
> >     integer, pointer :: k
> >     data k/j/
> >     if (i /= 0) then
> >        j = i
> >     else
> >        j = 42
> >     end if
> >     print *, k
> > end subroutine
> >
> > Of course, I could be wrong.
> >
> For me, the question boils down to whether the data statement means "=" 
> or whether it has been extended to also mean "=>".

This is exactly what I think has been done.  It seems
that there is an assumption that SAVE and TARGET means
the address of 'j' above is 'constant'.  So, the data
statement associates 'k' with that address not 'j's
actually value.

> All specifications 
> containing initial-data-target always show it to the right of "=>", not 
> "=". It seems a perfectly reasonable interpretation to say that 
> assignment with a data statement means "=", in which case 
> initial-data-target cannot be used because it is only specified to the 
> right of "=>". That said, your interpretation seems equally valid, 
> provided we are extending the data statement to provide pointer 
> assignment. I consider the data statement to be somewhat archaic, and 
> would be disappointed at it being extended when the second example is so 
> much cleaner.

Same here with the disappointment.  Well, I'm subscribed to
the J3 mailing list.  I suppose I can send an email to the
list and ask.  I'll also hunt around for the J3 paper, which
provided the rationale and modification.

Oh, I also sent the above subroutine to comp.lang.fortran
so see what others have to say.

-- 
Steve
20170425 https://www.youtube.com/watch?v=VWUpyCsUKR4
20161221 https://www.youtube.com/watch?v=IbCHE-hONow



More information about the Fortran mailing list