Intel® Fortran Compiler 17.0 Developer Guide and Reference
A module variable or a common block can interoperate with a C global variable if the Fortran entity uses the BIND attribute and the members of that entity are also interoperable. For example, consider the entities c_extern, c2, com and single in the following module:
Interoperability Example |
---|
|
These can interoperate with the following C external variables |
---|
int c_extern; long myVariable; struct {float r, s;} com; float single; |
Accessing Global Parameters Example |
---|
|
In Fortran, a variable can access a global parameter by using the standard BIND C attribute.
In the above, two external variables are created (the latter with proper case and decoration): idata and foo_mp_rdata.
Use the BIND attribute to resolve name discrepancies with C.
Global Variable Statement Example |
---|
int idata[20]; // declared as global (outside of any function) |
Fortran can declare the variable global (COMMON) and other languages can reference it as external |
---|
|
Use of BIND(C) above means that the name will be appropriately decorated for the target and made lowercase.
In C, the variable is referenced as an external with the statement |
---|
//C code with external reference to pi extern float pi; |
Note that the global name C references is the name of the Fortran common block (pi), not the name of a variable within a common block (pi_r). Therefore, you cannot use blank common (unnamed) to make data accessible between C and Fortran.