
-----------------------------------
jomarin
Fri Dec 05, 2008 8:09 am

Strange behavior when compiling C++ for Fortran
-----------------------------------
Hi everybody,

I need to call a C++ routine from a Fortran code. After some research on the internet, I found a solution using g++ and g77.
The problem is that I get some strange behavior, concerning the memory managment. The code of the small example is attached to this topic. Here is the contents :

file testmac.f :

C
      INTEGER*4 sum
      INTEGER*4 im0,im1, im2, im3, im4, im5
      
C
      im0=41
      im1=42
      im2=43
      im3=44
      im4=45
      im5=46
      
      WRITE(*,*) im0,im1,im2,im3,im4,im5
      
      CALL MAC(im0,im1,im2,im3,im4,im5)
      
C
      sum=im0+im1+im2+im3+im4+im5
      
      WRITE(*,*) sum
            
      WRITE(*,*) im0,im1,im2,im3,im4,im5
      WRITE(*,*) sum

C
      STOP
      END


File mac.cpp

#include "mac.h"

#include 

using namespace std;

// ################################################################## 
// Getting MAC Address via popen() within C++-program in Windows 2000 
// ################################################################## 


#define MAC_ADDRESS_SIZE 17 



// ===================================== 
void __stdcall mac_(int *v1,int *v2,int *v3,int *v4,int *v5,int *v6) 
{   

  cout 