02.07.2014 Views

Intel(R) Fortran Compiler for Linux* Systems User's Guide Volume I ...

Intel(R) Fortran Compiler for Linux* Systems User's Guide Volume I ...

Intel(R) Fortran Compiler for Linux* Systems User's Guide Volume I ...

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>Intel</strong>® <strong>Fortran</strong> <strong>Compiler</strong> <strong>for</strong> <strong>Linux*</strong> <strong>Systems</strong> <strong>User's</strong> <strong>Guide</strong> <strong>Volume</strong> I: Building<br />

Applications<br />

External variables are case-sensitive, so the cases must be matched between<br />

different languages, as discussed in the section on naming conventions.<br />

Common external data exchange is described in the following sections:<br />

• Using Global Variables<br />

• Using <strong>Fortran</strong> Common Blocks and C Structures<br />

Using Global Variables in Mixed-Language<br />

Programming<br />

A variable can be shared between <strong>Fortran</strong> and C by declaring it as global (or<br />

COMMON) in one language and accessing it as an external variable in the other<br />

language. In <strong>Fortran</strong> programs, variables must be passed as arguments.<br />

In <strong>Fortran</strong>, a variable can access a global parameter by using the EXTERN<br />

option <strong>for</strong> ATTRIBUTES. For example:<br />

!DEC$ ATTRIBUTES C, EXTERN :: idata<br />

INTEGER idata (20)<br />

EXTERN tells the compiler that the variable is actually defined and declared<br />

global in another source file. If <strong>Fortran</strong> declares a variable external with<br />

EXTERN, the language it shares the variable with must declare the variable<br />

global.<br />

In C, a variable is declared global with the statement:<br />

int idata[20]; // declared as global (outside of any function)<br />

<strong>Fortran</strong> can declare the variable global (COMMON) and other languages can<br />

reference it as external:<br />

! <strong>Fortran</strong> declaring PI global<br />

REAL PI<br />

COMMON /PI/ PI ! Common Block and variable have the same name<br />

In C, the variable is referenced as an external with the statement:<br />

//C code with external reference to PI0<br />

extern float PI;<br />

194

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!