This is the mail archive of the
fortran@gcc.gnu.org
mailing list for the GNU Fortran project.
Re: Re-examining PR61933 negative unit numbers
- From: Janne Blomqvist <blomqvist dot janne at gmail dot com>
- To: Jerry DeLisle <jvdelisle at charter dot net>
- Cc: gfortran <fortran at gcc dot gnu dot org>
- Date: Mon, 29 Dec 2014 17:03:18 +0200
- Subject: Re: Re-examining PR61933 negative unit numbers
- Authentication-results: sourceware.org; auth=none
- References: <54A0891C dot 6010706 at charter dot net>
On Mon, Dec 29, 2014 at 12:50 AM, Jerry DeLisle <jvdelisle@charter.net> wrote:
> I found some time during the Holidays to get back to this PR.
Thanks for looking into this.
> I think the solution depends on how we define whether or not a UNIT exists.
> All the back and forth emails and c.l.f discussions did not help me much and
> were leaning toward just letting any UNIT exist regardless except -1.
>
> Combing through the standard I find the following:
>
> "The unit identified by a NEWUNIT value shall not be preconnected."
>
> To me this means I can do write(10,*) without explicitly connecting UNIT 10
> with an open statement, but I can not do write(-10,*).
IIRC preconnected units are just those that are connected when the
program starts. In the case of gfortran, that would be std{in,out,err}
(apparently back in the days there were systems where some tape drive
was preconnected etc., but that is irrelevant here).
> Likewise, if iunit = -10, I can not do write(iunit, *) unless UNIT -10 was
> previously connected with an OPEN(NEWUNIT=someunit, ...). I disregard
> whether or not the programmer "knows" the value of the unit number somehow.
> I think that if one tries to write to a negative unit that was not
> established with a NEWUNIT specifier, then this is an error.
Yes. I think another way of saying the same is that the only way to
create a unit with a negative unit number is with OPEN(NEWUNIT=...).
That is, such units can not be created "implicitly" by just writing to
it, as is the case for units with positive unit numbers.
> Elsewhere in the standard I find the following:
>
> "At any given time, there is a processor-dependent set of external units
> that exist for a program."
>
> This is talking about UNIT existence being processor-dependent. To me this
> means we have some flexibility regarding what we define as existence for a
> UNIT.
Hmm, I suppose so. I'm not really sure what the above standard quote
tries to say.
> Proposed:
>
> I would like to recommend that we define for gfortran that an external UNIT
> exists if it is preconnected or if it does not require an explicit OPEN to
> be connected, or if it has been connected via an OPEN (with or without
> NEWUNIT being used).
>
> With this suggested definition INQUIRE(UNIT=someunit, EXISTS=unit_exists)
> has some meaningful usefulness. Further, this would allow a programmer to
> find out what negative units have been connected or are still connected. I
> am not suggesting that "usefulness" is some sort of universally understood
> thing or has any implied correctness. I am just asking myself what is the
> point of testing for existence of a UNIT if one does not define existence.
> And...I am trying to get an agreed to definition at least for gfortran.
>
> Is this definition OK with the gfortran team?
I wonder, why treat negative unit numbers differently? IMHO the
"obvious" definition would be that the unit exists if it is connected
at the moment (from an implementation standpoint, a gfc_unit
structure exists for it, find_unit() returns non-NULL etc.). With
that definition, INQUIRE(unit=someunit, exists=unit_exists) answers
the question "is this unit number currently in use?". Always saying
.true. for positive unit numbers (which your definition would imply,
IIUIC) is not particularly useful, is it?
--
Janne Blomqvist