------- Comment #7 from burnus at gcc dot gnu dot org  2008-08-07 19:48 -------
> The print*, (or write(*,*)) statement certainly _IS_ standard Fortran 77 and
> its ubiquitousness should make fixing this bug a priority.

The * is standard Fortran 66 to 2008, however, its interpretation was not
well-defined before Fortran 2003. You rely on an implementation choice of a
certain compiler and not on the standard. Even worse: With Fortran 2003 your
interpretation is opposite to what is written in the standard, which means that
gfortran will not change.

 * * *

May I quote from the Fortran 2003 standard (9.4 File connection):

"An asterisk identifies particular processor-dependent external units that are
preconnected for formatted sequential access (9.5.3.2). These units are also
identified by unit numbers defined by the named constants INPUT_UNIT and
OUTPUT_UNIT of the ISO_FORTRAN_ENV module (13.8.2)."

That is what gfortran does: INPUT_UNIT is 5, OUTPUT_UNIT is 6 and ERROR_UNIT is
0, the numbers are extremely popular choices though not defined in any Fortran
standard. Note especially the word "PRE-CONNECTED". The connection of these
units can be changed via

"9.4.5 The OPEN statement
"An OPEN statement initiates or modifies the connection between an external
file and a specified unit. [...] If a unit is connected to a file that exists,
execution of an OPEN statement for that unit is permitted."

Thus if one does
  open(6,file="foo.dat")
one changes the connection of unit 6 to point to "foo.dat" instead of to
standard out. Since OUTPUT_UNIT now points to "foo.dat", also unit=* (for
PRINT/WRITE) points to "foo.dat"

 * * *

It might be annoying that your old program does not work, but it was never
standard conform (at least not to the ISO Fortran 77/90/95/2003/2008 standard)
but it relied on a particular implementation choice which is incompatible with
the Fortran 2003 standard.

Once compiler which treated UNIT=* and UNIT=6 differently was the Intel Fortran
compiler, ifort alias ifc. But newer versions follow the Fortran 2003 standard,
even though they offer the option:

-assume old_unit_star      The READs or WRITEs  to  UNIT=*  go  to
                           stdin  or  stdout, respectively, even if
                           UNIT=5  or  6  has  been  connected   to
                           another file.

(Older version connected * to negative units, if I recall correctly, thus "*"
was something like -2 (guessed number) and thus 6 and '*' could be connected to
different files - both were preconnected to stdout.)

Intel introduced that option to be compatible with older version of ifort,
which have behaviours which clash with newer Fortran standard. As gfortran (and
not even its predecessor g77) had never implement it in a F2003 incompatible
way, there is no reason to implement such option, especially as most of the
time such programs are not really broken, only the output goes to the "wrong"
place.

 * * *

As a general advice: For file I/O one should use UNITs > 10 to make
(relatively) sure they do not clash with the INPUT/OUTPUT/ERROR_UNIT of a given
compiler; with Fortran 2008 one can let OPEN do the job to assign a free unit
[not yet implemented in gfortran].


-- 

burnus at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |burnus at gcc dot gnu dot
                   |                            |org


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

Reply via email to