- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I tried to use a global variable PI in C and FORTRAN codes.
But, it didn't work. Anyone could help me? Thanks.
*****************************************
In C code:
extern float PI;
extern "C" float PI_N(float b)
{
return PI*b;
}
extern "C" float PI_N(float b)
{
return PI*b;
}
*****************************************
In FORTRAN code:
module mod
interface
real function PI_N(b)
!dec$ attributes C ::add
!dec$ attributes value :: b
real::b
end function PI_N
end interface
end module mod
interface
real function PI_N(b)
!dec$ attributes C ::add
!dec$ attributes value :: b
real::b
end function PI_N
end interface
end module mod
program test1
use mod
implicit none
real::b,res,PI
common /PI/PI
PI=3.1416
b=5.0
res=PI_N(b)
print*,res
end program test1
use mod
implicit none
real::b,res,PI
common /PI/PI
PI=3.1416
b=5.0
res=PI_N(b)
print*,res
end program test1
Link Copied
1 Reply
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I got it!
I should add "C" at the line whereI declared the global variable.
extern "C" float PI;
![](/skins/images/8B5EA638CA3587CA763EE9EF53643DD4/responsive_peak/images/icon_anonymous_message.png)
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