[Patch, FORTRAN] PR61933 Inquire on Internal Unit
Jerry DeLisle
jvdelisle@charter.net
Sun Sep 7 17:29:00 GMT 2014
On 06/09/14 23:44, Janne Blomqvist wrote:
> On Sun, Sep 7, 2014 at 7:35 AM, Jerry DeLisle <jvdelisle@charter.net> wrote:
>> On 06/09/14 21:08, Janne Blomqvist wrote:
>>> On Sun, Sep 7, 2014 at 12:51 AM, Jerry DeLisle <jvdelisle@charter.net> wrote:
>>>> Hi,
>>>>
>>>> The attached patch adds a compile time check for negative unit numbers given in
>>>> an INQUIRE statement. A new test case is provided and one updated.
>>>
>>> What about units opened with newunit= ? Those have negative unit
>>> numbers. It seems strange that one wouldn't be allowed to inquire such
>>> units? Or if that indeed is the case, I suggest it's a bug in the
>>> standard (one can imagine such happening by forgetting to update
>>> inquire constraints after adding newunit= in f2003).
>>>
>>> program negunit
>>> implicit none
>>> logical :: file_exists
>>> integer :: u
>>> open(newunit=u, file="test.dat")
>>> inquire(unit=u, exist=file_exists)
>>> write(*,*) u, file_exists
>>> close(u, status="delete")
>>> end program negunit
>>>
>>
>> I was thinking of the same issue. The front end patch is correct.
>
> Is it? Is it really the intention that negative units are allowed if
> the specifier is a variable, but not if it is a constant? Consider the
> following, admittedly silly, example modified from the previous one:
>
> program negunit
> implicit none
> logical :: file_exists
> integer :: u
> open(newunit=u, file="test.dat")
> ! By secret magic I know that u=-10
> inquire(unit=-10, exist=file_exists)
The Standard clearly forbids using a negative constant syntax wise.
If the user uses a previously assigned newunit variable or other variable, then
the negative unit number value is used to search for the previously connected
negative unit and confirm that it has been indeed connected. The only way it
could have been connected as a negative unit is if the NEWUNIT= was used to
automatically assign the value. In other words, when the gfc_unit treap is
searched and it is found, then it has been connected and exists.
If a user tries something like:
u = -10
open(unit=u, file="test.dat")
That's illegal. It gets down to the only way a negative unit can get connected
is through NEWUNIT.
Jerry
More information about the Fortran
mailing list