This is the mail archive of the fortran@gcc.gnu.org mailing list for the GNU Fortran 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]

Windows applications, bind C and Cygwin64


The following test case

$ cat test_c_long.f90
program test_c_long
  use, intrinsic :: iso_c_binding
  print *, 'C_LONG = ',C_LONG
end program test_c_long


on Cygwin64 prints C_LONG = 8 when compiled with gfortran-4.8.1 (which produces Cygwin64 native binaries) and prints C_LONG = 4 when compiled with x86_64-w64-mingw32-gfortran-4.8.1 (which produces Windows 64 native binaries)[1]


This causes issues trying to run Windows applications translated into Fortran with the iso_c_bindig technique.

For example, interfacing GetClientRect() [2] with:

integer, parameter, public :: HANDLE_T = C_INTPTR_T
integer, parameter, public :: LONG_T = C_LONG
integer, parameter, public :: BOOL_T = CINT_T
integer, parameter, public :: HWND_T = HANDLE_T

public RECT_T
  type, bind(C) :: RECT_T
     integer(LONG_T) :: left
     integer(LONG_T) :: top
     integer(LONG_T) :: right
     integer(LONG_T) :: bottom
  end type RECT_T

public GetClientRect
  interface
     function GetClientRect(hWnd,lpRect) bind(C,name='GetClientRect')
       import
       !GCC$ ATTRIBUTES STDCALL :: GetClientRect
       integer(BOOL_T) :: GetClientRect
       integer(HWND_T), intent(in), value :: hWnd
       type(RECT_T), intent(out) :: lpRect
     end function GetClientRect
  end interface

[...]

type(RECT_T) :: rect
[...]
dummy = GetClientRect(hWnd,rect)

builds on Cygwin64 with [1]

gfortran-4.8.1                       Generating Cygwin64 binaries
i686-pc-cygwin-gfortran-4.7.3        Generating Cygwin32 binaries
i686-w64-mingw32-gfortran-4.8.1      Generating Windows 32 binaries
x86_64-w64-mingw32-gfortran-4.8.1    Generating Windows 64 binaries
i686-pc-mingw32-gfortran-4.7.3       Generating Windows 32 binaries

but produces wrong results [3] only with gfortran-4.8.1 which is the only compiler with C_LONG = 8. If in the above definitions I set at hand LONG_T = 4 then the applications works also with gfortran-4.8.1.


I wonder if this is to be expected and why x86_64-w64-mingw32-gfortran-4.8.1, which is a Cygwin64 compiler generating 64 bit binaries, has C_LONG = 4 and not 8...

Surely I missing something..


Ciao,
 Angelo.

---
[1] All the compilers are installed by means of Cygwin64 packages manager (setup-x86_64.exe)

[2] http://msdn.microsoft.com/en-us/library/windows/desktop/ms633503(v=vs.85).aspx

[3] For example, in rect is returned something like 0, 1554778161736, 1, 34029008.


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