next up previous 252
Next: Other Operating Systems
Up: VAX/VMS
Previous: Function Values

Global Data

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

Example - A VAX FORTRAN labelled 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 VAX FORTRAN and VAX 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 VAX FORTRAN blank common block, then the corresponding VAX C structure should be called $BLANK.

Example - A VAX FORTRAN labelled 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: Other Operating Systems
Up: VAX/VMS
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