Fortran and underscores

From GHER

Jump to: navigation, search

Some Fortran compiles may add an underscore to sunroutine and function names. This is an problem when interfacing C and Fortran code.

Here are two test programs:

testf77.f

      program fcallc
      i=4
      CALL doubling(i)
      PRINT *,i
      stop
      end


Compiler Generated code
g77 doubling_
g95 doubling_
gfortran doubling_
ifort doubling_
pgf90 doubling_
pgf77 doubling_

testf77b.f

      program fcallc
      i=4
      CALL doubling_this(i)
      PRINT *,i
      stop
      end


Compiler Generated code
g77 doubling_this__
g95 doubling_this__
gfortran doubling_this_
ifort doubling_this_
pgf90 doubling_this_
pgf77 doubling_this_

g77 and g95 add two underscore when the function name already has one.

Personal tools