This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug libfortran/24576] Fortran I/O to same unit number in main program and in a shared library



------- Comment #6 from sgk at troutmask dot apl dot washington dot edu  2005-10-29 02:34 -------
Subject: Re:  Fortran I/O to same unit number in main program and in a shared
library

On Sat, Oct 29, 2005 at 01:52:48AM -0000, iwan wrote:
> If I look at section 5.5.2.3 of the 2003 Standard about common blocks, 

The standard has no concept of "program".  It does have
a concept of "program units"  See section 11 and 12.

> I find that 
> "Within a program, the common block storage sequences of of all 
> non-zero sized common blocks with the same name have the same 
> first storage unit...".

Non-sequitur.

storage unit != external unit (which is connected to a file).

> This is the behavior one gets with the Intel and PGI compilers on 
> Linux and this is the behavior I remember from years ago on 
> IRIX and SunOS workstations.

It is not uncommon for vendors to add extensions to their
products even when the extension violates the standards.

Following Note 9.9 in the Final Committe Draft of the Fortran
95 standard, one finds:

  A unit shall not be connected to more than one file at the
  same time.

It does not matter if the subprogram is dynamically loaded
into memory.  If the main program has associated unit=1 with
a file and you call a subprogram from the shared library and
it associates unit=1 with a different file, then your program
is nonconforming.

To make your program portable, you should use the inquire
function to obtain an unused unit.

function getunit()
   implicit none
   integer getunit
   logical inuse
   getunit = 1
   do 
      inquire(unit = getunit, opened = inuse)
      if (inuse .eqv. .false.) exit
      getunit = getunit + 1
   end do
end function getunit

program a
  integer fd
  integer, external :: getunit
  fd = getunit()
  open(unit=fd, file'yada')
end program a


-- 


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]