Difference between revisions of "Main Page/C Fortran"

From Nekcem
Jump to navigationJump to search
(Created page with "2.1- SUBROUTINE For a Fortran CALL SUB the corresponding C routine has to be named: SUB all upper case on Cray with cft77 compiler sub all lower case on Apollo with ft…")
 
 
(4 intermediate revisions by the same user not shown)
Line 1: Line 1:
 +
== PGI compiler name mangling convention ==
 +
When programs are compiled using one of the PGI Fortran compilers on UNIX systems, an underscore is appended to Fortran global names (names of functions, subroutines and common blocks).
 +
This mechanism distinguishes Fortran name space from C/C++ name space.
 +
 +
If you call a C/C++ function from Fortran, you should rename the C/C++ function by appending an underscore (or use C$PRAGMA C in the Fortran program, refer to Chapter 9, Optimization Directives and Pragmas, for details on C$PRAGMA C)
 +
 +
If you call a Fortran function from C/C++, you should append an underscore to the Fortran function name in the calling program.
 +
(source: http://www.tacc.utexas.edu/services/userguides/pgi/pgiws_ug/pgi32u07.htm#Heading93)
 +
 +
==Name mangling in Fortran (from Wikipedia)==
 +
 +
Name mangling is also necessary in Fortran compilers, originally because the language is case insensitive. Further mangling requirements were imposed later in the evolution of the language because of the addition of modules and other features in the Fortran 90 standard. The case mangling, especially, is a common issue that must be dealt with in order to call Fortran libraries (such as LAPACK) from other languages (such as C).
 +
 +
Because of the case insensitivity, the name of a subroutine or function "FOO" must be converted to a canonical case and format by the Fortran compiler so that it will be linked in the same way regardless of case. Different compilers have implemented this in various ways, and no standardization has occurred.
 +
 +
The AIX and HP-UX Fortran compilers convert all identifiers to lower case ("foo"), while the Cray Unicos Fortran compilers converted identifiers all upper case ("FOO").
 +
 +
The GNU g77 compiler converts identifiers to lower case plus an underscore ("foo_"), except that identifiers already containing an underscore ("FOO_BAR") have two underscores appended ("foo_bar__"), following a convention established by f2c.
 +
 +
Many other compilers, including SGI's IRIX compilers, gfortran, and Intel's Fortran compiler, convert all identifiers to lower case plus an underscore ("foo_" and "foo_bar_").
 +
 +
Identifiers in Fortran 90 modules must be further mangled, because the same subroutine name may apply to different routines in different modules.
 +
 +
 +
 +
 +
 +
 +
 +
 
2.1- SUBROUTINE
 
2.1- SUBROUTINE
  

Latest revision as of 12:49, 19 May 2011

PGI compiler name mangling convention

When programs are compiled using one of the PGI Fortran compilers on UNIX systems, an underscore is appended to Fortran global names (names of functions, subroutines and common blocks). This mechanism distinguishes Fortran name space from C/C++ name space.

If you call a C/C++ function from Fortran, you should rename the C/C++ function by appending an underscore (or use C$PRAGMA C in the Fortran program, refer to Chapter 9, Optimization Directives and Pragmas, for details on C$PRAGMA C)

If you call a Fortran function from C/C++, you should append an underscore to the Fortran function name in the calling program. (source: http://www.tacc.utexas.edu/services/userguides/pgi/pgiws_ug/pgi32u07.htm#Heading93)

Name mangling in Fortran (from Wikipedia)

Name mangling is also necessary in Fortran compilers, originally because the language is case insensitive. Further mangling requirements were imposed later in the evolution of the language because of the addition of modules and other features in the Fortran 90 standard. The case mangling, especially, is a common issue that must be dealt with in order to call Fortran libraries (such as LAPACK) from other languages (such as C).

Because of the case insensitivity, the name of a subroutine or function "FOO" must be converted to a canonical case and format by the Fortran compiler so that it will be linked in the same way regardless of case. Different compilers have implemented this in various ways, and no standardization has occurred.

The AIX and HP-UX Fortran compilers convert all identifiers to lower case ("foo"), while the Cray Unicos Fortran compilers converted identifiers all upper case ("FOO").

The GNU g77 compiler converts identifiers to lower case plus an underscore ("foo_"), except that identifiers already containing an underscore ("FOO_BAR") have two underscores appended ("foo_bar__"), following a convention established by f2c.

Many other compilers, including SGI's IRIX compilers, gfortran, and Intel's Fortran compiler, convert all identifiers to lower case plus an underscore ("foo_" and "foo_bar_").

Identifiers in Fortran 90 modules must be further mangled, because the same subroutine name may apply to different routines in different modules.





2.1- SUBROUTINE

For a Fortran CALL SUB the corresponding C routine has to be named:

SUB

   all upper case on Cray with cft77 compiler 

sub

   all lower case on Apollo with ftn compiler 
   case insensitive on IBM/370 and VMS 

sub_

   lower case with underscore added on all other system