Microsoft KB Archive/60076

= Accessing Mixed-Language, External Variables in FORTRAN =

Article ID: 60076

Article Last Modified on 12/1/2003

-

APPLIES TO


 * Microsoft FORTRAN Compiler 4.1
 * Microsoft FORTRAN Compiler 5.0
 * Microsoft FORTRAN Compiler 5.1
 * Microsoft FORTRAN Compiler 4.1
 * Microsoft FORTRAN Compiler 5.0
 * Microsoft FORTRAN Compiler 5.1

-



This article was previously published under Q60076



SUMMARY
The following is a sample C and FORTRAN mixed-language program demonstrating how to access external variables from within Microsoft FORTRAN.

FORTRAN Code
SUBROUTINE ASSIGN INTEGER*2 X [EXTERN, ALIAS:'_extrn']

X = 2 END

C Code

 * 1) include 

extern void fortran assign(void); int extrn;

main {   extrn = 5; printf(&quot;Before call to FORTRAN: %d\n&quot;,extrn); assign; printf(&quot; After call to FORTRAN: %d\n&quot;,extrn); }



MORE INFORMATION
To use global variables exported from another language in FORTRAN, the EXTERN attribute must be used. EXTERN tells the FORTRAN compiler that the variable is not local to the FORTRAN subroutine or function. Variables declared EXTERN will instead be resolved by the linker. You can use the ALIAS attribute to assign a different name to the imported variable; in this example, it is required because the underscore prepended by the C compiler is invalid in the FORTRAN naming convention.

No modifications should be necessary for the exporting module to allow FORTRAN to import the global variable(s).

Additional query words: nofps kbinf 4.10 5.00 5.10

Keywords: KB60076

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.