(j3.2006) badly worded semantics for the IMPORT statement
Robert Corbett
Robert.Corbett
Tue Dec 4 21:20:26 EST 2007
Bill Long wrote:
>
> Robert Corbett wrote:
>
>>>I'd note that essentially the same statement appears twice, at [260:4-5]
>>>and [260:11-12], but with different sentence structure. My wording
>>>above follows more closely the second sentence in the standard. Maybe
>>>it would be clearer, and more consistent, to use the same sentence form
>>>in both places.
>>>
>>>Cheers,
>>>Bill
>>>
>>>
>>>Robert Corbett wrote:
>>>
>>>
>>>
>>>>Someone here at Sun recently asked why it made a difference whether
>>>>a variable named in an IMPORT statement was assigned a value. He
>>>>pointed out that Section 12.3.2.1 of the Fortran 2003 standard states
>>>>
>>>> An entity that is imported in this manner and is defined
>>>> ^^^^^^^
>>>> in the host scoping unit shall be explicitly declared
>>>> prior to the interface body.
>>>>
>>>>Perhaps it would be better to say "declared" instead of "defined."
>>>>
>>>>Bob Corbett
>>>>
>>>>
>>
>>Consider the module
>>
>> MODULE MOD
>> INTERFACE
>> SUBROUTINE SUBR(A)
>> IMPORT
>> DIMENSION A(N)
>> END SUBROUTINE
>> END INTERFACE
>> INTEGER, PARAMETER :: I = BIT_SIZE(N)
>> END MODULE
>>
>>Applying the definition of "definition" given in Section 2.5.5
>>literally, this module is standard conforming unless the module
>>variable N is assigned a value. That is clearly not what was
>>intended, but it is what the standard says. I would prefer for
>>the standard to say what it means and means what it says.
>>
>>Bob Corbett
>>
>>
>
> I assume you think this module should not be standard conforming.
I don't think J3 intended for it to be standard conforming. From an
implementor's POV, I see no reason for the restriction. Fortran 90
and later versions of Fortran require two or more compilation passes,
which makes the restriction unnecessary. The restriction might be
there to enforce someone's idea of good style; otherwise, I see no
point to it.
> I can agree with that.
> How about the same module except where the INTEGER
> statement is before the INTERFACE block? If the intent of the standard
> is to relieve compilers from having to look ahead for declarations or
> definitions, then the modified module would seem OK.
>
> If the only issue is look ahead, then it would seem like the sentence
> could be reworded something like:
>
> "An entity that is imported in this manner shall be declared or defined
> prior to the interface body."
>
> Note that this also drops the "explicitly" to allow for implicit
> declaration, as in your module. Is this what you think the standard
> means (or should mean)? I agree that the current wording is muddled,
> combining "defined" (applies to variables and types) with "declared"
> (does not apply to types). However, I think the proposed alternative
> above really does say something different. I think an interp would be
> required for such a change.
Another case that occurred to me is the following:
MODULE MOD
DIMENSION M(10)
INTERFACE
SUBROUTINE SUBR(A)
IMPORT
DIMENSION A(M(1))
END SUBROUTINE
END INTERFACE
INTEGER M
END
Has M been "explicitly declared" before the IMPORT? What if the INTEGER
and DIMENSION statements are switched?
Bob Corbett
More information about the J3
mailing list