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/20788] Loading libgfortran.so clobbers C redirection of stdin


------- Additional Comments From fxcoudert at gcc dot gnu dot org  2005-04-15 13:48 -------
First: using stdio in a mixed Fortran/C is a small nightmare. For short term
purposes, I strongly suggest you use the GFORTRAN_STDIN_UNIT=-1 trick. That does
exactly what you want (that is, suggest that Fortran runtime library should not
mess with standard input).

Now, an intersting thing for wandering bug-fixers is that you can mix c and
fortran standard input if you disable preconnection and manually open
/proc/self/fd/0 to unit 5:

$ cat test.c 
#include <stdio.h>

void foo_(void)
{
    char buf[1024];
    while(1) {
      if(fgets(buf, 1024, stdin) == NULL) break;
      printf("%s", buf);
   }
}
$ gcc -c test.c
$ cat test1.f 
      external foo
      character*70 c
      read (*,'(A)') c
      print *, c
      print *, 'calling the C routine'
      call foo
      print *, 'end of the program'
      end
$ cat test2.f
      external foo
      character*70 c
      open (5, file='/proc/self/fd/0')
      read (*,'(A)') c
      print *, c
      print *, 'calling the C routine'
      call foo
      print *, 'end of the program'
      end
$ gfortran test1.f test.o
$ ./a.out < test.c       
 #include <stdio.h>                                                    
 calling the C routine
 end of the program
$ gfortran test2.f test.o
$ GFORTRAN_STDIN_UNIT=-1 ./a.out < test.c
 #include <stdio.h>                                                    
 calling the C routine
#include <stdio.h>

void foo_(void)
{
    char buf[1024];
    while(1) {
      if(fgets(buf, 1024, stdin) == NULL) break;
      printf("%s", buf);
   }
}
 end of the program


So, the question is: what is the difference between preconnection and manually
openning the unit? I did strace the two processes and I attach the diff of these
traces here (about 50 lines, easy to read). I think the solution to this problem
is here.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|2005-04-10 10:38:34         |2005-04-15 13:48:43
               date|                            |


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


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