experchange > fortran

Thomas Koenig (01-27-19, 10:13 PM)
Hi,

in a PR, I came across this rather strange program:

program p
real :: a(2,2)[*]
data a /4*0.0/
end

I find this code rather strange, but is it in fact valid?
steve kargl (01-27-19, 11:33 PM)
Thomas Koenig wrote:

> Hi,
> in a PR, I came across this rather strange program:
> program p
> real :: a(2,2)[*]
> data a /4*0.0/
> end
> I find this code rather strange, but is it in fact valid?


It is invalid code. From f2018,

C873 A data-stmt-object or data-i-do-object shall not be a coindexed variable.

You can look in gfc_match_data to find where best to issue an error message.
rbader (01-27-19, 11:58 PM)
Am Sonntag, 27. Januar 2019 22:33:20 UTC+1 schrieb steve kargl:
> Thomas Koenig wrote:
> It is invalid code. From f2018,
> C873 A data-stmt-object or data-i-do-object shall not be a coindexed variable.
> You can look in gfc_match_data to find where best to issue an error message.
> --
> steve


I disagree. The constraint does not apply to the program since no coindexed variable (viz a[j] vs. a) appears in the DATA statement.

Regards
Reinhold
Steve Lionel (01-28-19, 07:54 PM)
On 1/27/2019 4:58 PM, rbader wrote:
> I disagree. The constraint does not apply to the program since no coindexed variable (viz a[j] vs. a) appears in the DATA statement.


I agree with Reinhold - this is valid Fortran. The variable here gets
the SAVE attribute implicitly, but that is fine for a codimensioned
variable (C826). The effect is to initialize each image's part of the
array to the specified value.
gah4 (01-28-19, 10:07 PM)
On Monday, January 28, 2019 at 9:54:54 AM UTC-8, Steve Lionel wrote:

(snip on DATA statements and coarrays)

> I agree with Reinhold - this is valid Fortran. The variable here gets
> the SAVE attribute implicitly, but that is fine for a codimensioned
> variable (C826). The effect is to initialize each image's part of the
> array to the specified value.


It seems that coarrays are required to have either the SAVE or ALLOCATABLE attribute, or be dummy variables. Specifically, they can't be automatic.

So, yes, it makes sense to initialize one's own image, but not another image.

But I don't at all understand how the words say this.
Steve Lionel (01-29-19, 02:55 AM)
On 1/28/2019 3:07 PM, gah4 wrote:
> On Monday, January 28, 2019 at 9:54:54 AM UTC-8, Steve Lionel wrote:
> (snip on DATA statements and coarrays)
> It seems that coarrays are required to have either the SAVE or ALLOCATABLE attribute, or be dummy variables. Specifically, they can't be automatic.
> So, yes, it makes sense to initialize one's own image, but not another image.
> But I don't at all understand how the words say this.


I think it's more important that you didn't find words that say you
CAN'T do this. Otherwise, a coarray in a DATA statement is just like a
coarray (without an image selector) elsewhere in the program, meaning
the local image's coarray. ("On its own image, a coarray can also be
accessed without use of cosubscripts" 5.4.7p4)
Similar Threads