next up previous 252
Next: DEC Unix
Up: Sun
Previous: Function Values

Global Data

Although FORTRAN and C use different method for representing global data, it is actually very easy to mix them. If a Sun FORTRAN common block contains a single variable or array, then the corresponding C variable simply needs to be declared as extern and the two variables will use the same storage.

Example - A labelled Sun FORTRAN common block containing a single variable.
FORTRAN common block:
      CHARACTER*(10) STRING
      COMMON /BLOCK/ STRING

C external variable:

      extern char block_[10];

Note that the name of the C variable corresponds to the name of the FORTRAN common block, not the name of the FORTRAN variable. This example shows that you can use the same storage area for both Sun FORTRAN and C strings, however, you must still beware of the different way in which FORTRAN and C handle the end of a string.

If the FORTRAN common block contains more than one variable or array, then the C variables must be contained in a structure.

If you wish to access the Sun FORTRAN blank common block, then the corresponding C structure should be called _BLNK__.

Example - A labelled Sun FORTRAN common block containing several variables.
FORTRAN common block:
      INTEGER I,J,K
      COMMON /NUMS/ I,J,K

C external variable:

      extern struct { int i,j,k; } nums_;



next up previous 252
Next: DEC Unix
Up: Sun
Previous: Function Values

CNF and F77 Mixed Language Programming -- FORTRAN and C
Starlink User Note 209
P.M. Allan
A.J. Chipperfield
R.F. Warren-Smith
19 January 2000
E-mail:ussc@star.rl.ac.uk