help-gplusplus
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Why can fail Mingw to reuse a C++ struct in a COMMON in FORTRAN?


From: Pedro567
Subject: Why can fail Mingw to reuse a C++ struct in a COMMON in FORTRAN?
Date: Tue, 04 May 2010 15:46:40 -0000
User-agent: G2/1.0

We are having a problem to match properly a  C++ struct exported as
dll using GNU g++ 4.4.0 with a COMMON block in Fortran using GNU
gfortran 4.4.0. Tt works properly in Linux version, but not with
Mingw. Probably we are missing something in this platform. Any help
will be welcomme.

Code in C++ (compiled as a dll):
extern "C"
{
extern struct {
  int   n;
  int   k;



}  area_ ;
}


extern "C" __declspec(dllexport) void view_() { area_.n= 83;
printf("c
++, n=%d , k=%d \n",area_.n,area_.k); return; }

Code in FORTRAN (main program calling the previous dll):
      BLOCK DATA t
      INTEGER N,K
      COMMON /AREA/ N,K
      END


        PROGRAM P456
       COMMON /AREA/ N,K
        N = 3
        K = 6
        WRITE(*,*) N,K
        CALL view
        WRITE(*,*) N,K
        END PROGRAM


We add an extra C file to the dll for compiling independly of
FORTRAN:
__declspec(dllexport) struct {
  int   n;
  int   k;



}  area_ ;


Using GNU g++ and gfortran in Mingw the area_ struct is not properly
shared and two
copies are used in memory, the output is wrong:
3   6
83 0
3  6
But using GNU g++ and gfortran 4.4 in Linux Debian and Microsoft C++
6.0, 2003 and 2008 we
obtain a correct result:
3  6
83  6
83  6

The AREA common block in FORTRAN does not point to the same struct
area in C++ dll, why?


Why fails only in Windows platform using GNU C++ compiler?


Thanks for any help
Pedro




reply via email to

[Prev in Thread] Current Thread [Next in Thread]