To assist you in writing mixed-language programs, XL Fortran follows a consistent
set of rules when translating the name of a global entity into an external
name that the linker can resolve:
- Both the underscore (_) and the dollar sign ($)
are valid characters anywhere in names.
Because names that begin with an
underscore are reserved for the names of library routines, do not use an underscore
as the first character of a Fortran external name.
To avoid conflicts
between Fortran and non-Fortran function names, you can compile the Fortran
program with the -qextname option. This option adds an underscore
to the end of the Fortran names. Then use an underscore as the last character
of any non-Fortran procedures that you want to call from Fortran.
- Names can be up to 250 characters long.
- Program and symbolic names are interpreted as all lowercase by default.
If you are writing new non-Fortran code, use all-lowercase procedure names
to simplify calling the procedures from Fortran.
You can use the -U option or the @PROCESS MIXED directive if you want the
names to use both uppercase and lowercase:
@process mixed
external C_Func ! With MIXED, we can call C_Func, not just c_func.
integer aBc, ABC ! With MIXED, these are different variables.
common /xYz/ aBc ! The same applies to the common block names.
common /XYZ/ ABC ! xYz and XYZ are external names that are
! visible during linking.
end
- Names for module procedures are formed by concatenating __ (two underscores), the module name, _IMOD_ (for intrinsic
modules) or _NMOD_ (for non-intrinsic modules), and the name
of the module procedure. For example, module procedure MYPROC in
module MYMOD has the external name __mymod_NMOD_myproc.
Note:
Symbolic debuggers and other tools should account for this naming
scheme when debugging XL Fortran programs that contain module procedures.
For example, some debuggers default to lowercase for program and symbolic
names. This behavior should be changed to use mixed case when debugging XL
Fortran programs with module procedures.
- The XL compilers generate code that uses main as
an external entry point name. You can only use main as an external
name in these contexts:
- A Fortran program or local-variable name. (This restriction means that
you cannot use main as a binding label, or for the name of an external
function, external subroutine, block data program unit, or common block. References
to such an object use the compiler-generated main instead of your
own.)
- The name of the top-level main function in a C program.
- Some other potential naming conflicts may occur when linking a program.
For instructions on avoiding them, see Avoiding naming conflicts during linking.
If you are porting your application from another system and
your application does encounter naming conflicts like these, you may need
to use the -qextname option.