- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I am having trouble getting information defined in a
C++ structure to be visible in Fortan and vice-versa.
C++ structure to be visible in Fortan and vice-versa.
The code below is from the Digital Visual Fortran Programmers
Guide (page 502-503).
Guide (page 502-503).
EXAMP_mp_MYDATA does not appear to be mapped to TYPE MYDATA in module EXAMP.
The local variables defined (A, I1, I2...) are visible and changeable
in both C++ and Fortran.
in both C++ and Fortran.
How do I get the C++ structure and the Fortran Type to be shared in both
languages ??
languages ??
Thanks,
stockmangl
stockmangl
Visual Fortran Standard Edition 6.6B
Visual C++ 6.0
Visual C++ 6.0
Code:
test_main.f90
!F90 F90 F90 F90 F90 F90 F90 F90 F90
module examp
real a(3)
integer*4 i1, i2
character(80) line
type mydata
sequence
integer*4 n
character(30) info
end type mydata
end module examp
real a(3)
integer*4 i1, i2
character(80) line
type mydata
sequence
integer*4 n
character(30) info
end type mydata
end module examp
program test_main
use examp
implicit none
EXTERNAL test_c
!tell the compiler to use lower-case names
!DEC$ ATTRIBUTES C::test_c
!DEC$ ATTRIBUTES C::test_c
TYPE(mydata) :: mydata_shared
mydata_shared%n = 3
!set value for mydata_shared%n. This should be visible and the same
!number when we get to C++
!number when we get to C++
print *,' in 1st fortran testing structure mydata_shared%n = ',mydata_shared%n
call test_c
print *,' after returning from c routine mydata_shared%n = ',mydata_shared%n
! we should see the same value here that was changed/set on the C++ side
print *,' '
a(1) = 33.0
print *,' testing locals... a = ',a(1)
call test_c
print *,' after returing from c routine... a = ',a(1)
stop
end
test_c.cpp
// C++ C++ C++ C++ C++ C++ C++ C++ C++
#include
extern "C" float EXAMP_mp_A[3];
extern "C" int EXAMP_mp_I1;
extern "C" int EXAMP_mp_I2;
extern "C" char EXAMP_mp_LINE[80];
extern "C"
{
struct {
int N;
char INFO[30];
} EXAMP_mp_MYDATA;
}
extern "C" int EXAMP_mp_I1;
extern "C" int EXAMP_mp_I2;
extern "C" char EXAMP_mp_LINE[80];
extern "C"
{
struct {
int N;
char INFO[30];
} EXAMP_mp_MYDATA;
}
extern "C" void test_c(void);
void test_c()
{
// we should set the same value that was changed/set on
// the fortran side
// the fortran side
printf(" in C routine, n = %d ",EXAMP_mp_MYDATA.N);
EXAMP_mp_MYDATA.N = 26;
// change the value of EXAMP_mp_MYDATA.N This should be
// visible and changed when we get to the Fortran side
printf(" in C routine A = %f
",EXAMP_mp_A[0]);
EXAMP_mp_A[0] = 45.0;
printf(" changed EXAMP_mp_A[0] to %f ",EXAMP_mp_A[0] );
}
Link Copied
0 Replies

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page