External data refers to data that is both static and public; that is, the data is stored in a set place in memory as opposed to being allocated on the stack, and the data is visible to other modules.
External data can be defined in C, C++, Pascal, and assembly language. Note that a data definition is distinct from an external declaration. A data definition causes a compiler to create a data object; an external declaration informs a compiler that the object is to be found in another module. FORTRAN can only define external data in COMMON blocks. (See “Common Blocks,” for more information about sharing external data with FORTRAN programs.)
There are three requirements for programs that share external data between languages:
One of the modules must define the data.
You can define a static data object in a C module by defining a data object outside all functions. (If you use the static keyword in C, however, the data object will not be made public.)
You can make a C++ data object visible to other languages by declaring it with the extern “C” linkage specification. However, you cannot use any C++ specific features of such data items. For example, you cannot call any member functions for an object declared extern “C”.
The other modules that will access the data must declare the data as external.
In C, you can declare data as external by using an extern declaration, similar to the extern declaration for functions. In FORTRAN and Pascal, you can declare data as external by adding the EXTERN attribute to the data declaration.
Resolve naming-convention differences.
In C, you can adopt the FORTRAN/Pascal naming convention by applying __fortran or __pascal to the data declaration. In C++, you can adopt the C naming convention by using the extern “C” linkage specification, and you can adopt the FORTRAN/Pascal naming convention by adding the __fortran or __pascal keywords. In FORTRAN and Pascal, you can adopt the C naming convention by applying the C attribute to the data declaration.