http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60596

--- Comment #7 from Steve Kargl <sgk at troutmask dot apl.washington.edu> ---
On Thu, Mar 20, 2014 at 04:25:16AM +0000, patnel97269-gfortran at yahoo dot fr
wrote:
> Ok so if I understand well, for gfortran once the input_unit
> is closed, the unit number corresponding to input_unit can
> be used for another file.

This is true for all standard conforming compilers, including
ifort.

> But, the input_unit is defined to be the standard input. 

This is only true if you don't do "close(input_unit)".  At
program start, input_unit is associated with the *preconnected*
file stdin (on FreeBSD /dev/stdin is a symlink to /dev/fd/0).
I've already quoted the standard:

   The CLOSE statement is used to terminate the connection
   of a specified unit to an external file.

Given the results that you showed.  ifort is clearly caching the
association of input_unit with stdin eventhough you've closed
the unit!  I consider this to be a bug.  Intel probably considers
this to be a faeture.

> 1) If one wants to reconnect to standard input socket (/dev or
> /proc) how to find out with gfortran without knowing the file path ? 

See Jerry's reply.  Use inquire() to determine the file name before
you close input_unit.  Also, Fortran 2008 standard has

   NOTE 9.17
   The only means of referencing a file that has been disconnected
   is by the appearance of its name in an OPEN or INQUIRE statement.  
   There might be no means of reconnecting an unnamed file once it
   is disconnected.

A NOTE in the Fortran standard is only an informative statement, and
a processor is not required to conform to its content.  This, INMSHO,
is strong evidence that the program you posted has a bug and ifort has
a bug (which Intel will brush aside as processor-dependent behavior).

> 2) it is allowed to change some properties of an already connected unit by
> calling the open function again without closing first. 
> When i do so , using 
> 
>   open(unit=input_unit,status='old' ,access='stream')
>   inquire(unit=input_unit,name=nm)
>   print *,nm
>   inquire(unit=input_unit,size=sz)
> 
> I get : 
> 
> At line 26 of file test2.f90 (unit = 5, file = 'stdin')
> Fortran runtime error: Cannot change ACCESS parameter in OPEN statement

Yes, you can use an OPEN statement with an already connected unit/file,
but there are restrictions.  You'll need to see your favorite Fortran
reference or section 9 of the Fortran standard.  Changing the access
method of an already connected unit seems to be one of those restrictions.

> 3) Ifort is automatically reconnecting input_unit to standard input when file
> is omitted, how is that a bug ?

I claim that it is.  Intel will claim that it is a feature.
In any event, this isn't a bug in gfortran.

Reply via email to