Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

How to declare a global variable?

weichao
Beginner
427 Views
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;
}
*****************************************
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
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
0 Kudos
1 Reply
weichao
Beginner
427 Views

I got it!

I should add "C" at the line whereI declared the global variable.

extern "C" float PI;

0 Kudos
Reply