From Bugzilla Helper: User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.0.1) Gecko/20021003 Description of problem: Using a main program in C and a subroutine in Fortran, where the Fortran uses isatty without using any other Fortran I/O, results in a segmentation fault at that point. Inserting another Fortran I/O operation before the call to isatty works around the problem. Alternatively, calling f_init explicitly from the C code before calling the Fortran also works. My problem occurs in a large complicated set of code mixing C and Fortran, but the example below illustrates the problem. Version-Release number of selected component (if applicable): gcc-g77-3.2-7 How reproducible: Always Steps to Reproduce: 1.Use a C main routine like: #include <stdio.h> int main(int argc, char **argv) { extern a_(int *result); int result = 0; a_(&result); printf("result = %d\n", result); return(0); } 2.and a Fortran subroutine like: subroutine a(result) integer result result = 1 if (isatty(6) .eqv. .true.) result = 2 return end 3. g77 -o mytest mytest.c mytest.for 4. ./mytest Actual Results: Segmentation fault Running with g77 -g and gdb: #0 0x42069ab7 in fileno_unlocked () from /lib/i686/libc.so.6 #1 0x4003c337 in G77_fnum_0 () from /usr/lib/libg2c.so.0 #2 0x4003c6e8 in G77_isatty_0 () from /usr/lib/libg2c.so.0 #3 0x080484e8 in a_ (result=0xbffff454) at mytest.for:5 #4 0x080484af in main (argc=1, argv=0xbffff4a4) at mytest.c:8 #5 0x420158f7 in __libc_start_main () from /lib/i686/libc.so.6 Expected Results: Should return "result = 1" or "result = 2" depending on whether output is redirected or not. Additional info: Inserting the line: f_init(); in the C code prior to calling the function "a_" works around the problem. Or, inserting the line: write(*,'($)') before the call to isatty in the Fortran also works around the problem, since write implicitly calls f_init. It is not a very serious bug, but one which proved rather hard to track down and I suspect is probably easy to fix, so it would be nice to see it fixed.
The g77 developers have confirmed the bug and the fix is indeed easy. Presumably it will be integrated into a future release.
Still present in gcc 3.4. Gfortran in gcc 4.0 appears to incorrectly declare isatty as integer instead of logical.
Correction: fixed in gcc 3.4. Accidentally ran the previous test against the installed 3.2 libg2c.so.