PRINT* in gfortran 4.2.0 compiled dll's needs CALL FLUSH to perform correctly
when called from gcc (3.4.2, 3.4.5, 4.1) compiled main. Reproducible sample:

$ gfortran -shared -o ftesti.dll ftesti.f90

ftesti.f90:
-----------
subroutine print_from_gfortran(txt)
  implicit none
  character :: txt
  print *,txt
end subroutine print_from_gfortran

$ gcc -o ctesti.exe ctesti.c

ctesti.c:
---------
#include <stdio.h>
#include <windows.h>

void print_from_gcc(char* txt) {
  printf("%s\n",txt);
}

int main(int argc, char** argv) {
  HINSTANCE handle=LoadLibrary("ftesti.dll");
  FARPROC print_from_gfortran=GetProcAddress(handle,"print_from_gfortran_");

  print_from_gcc     ("c");
  print_from_gfortran("f");
  print_from_gcc     ("c");
  print_from_gfortran("f");

  return 0;
}

Now, running ctesti.exe produces

c
c
f
f

Correct output should be

c
f
c
f

Adding CALL FLUSH in ftesti.f90 fixes the case:

ftesti.f90:
-----------
subroutine print_from_gfortran(txt)
  implicit none
  character :: txt
  print *,txt
  call flush
end subroutine print_from_gfortran


-- 
           Summary: gfortran print flush in dll
           Product: gcc
           Version: 4.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: mikko dot lyly at csc dot fi
  GCC host triplet: i686-pc-mingw32


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

Reply via email to