Sun Studio 12: Fortran Library Reference

1.1 Data Type Considerations

Unless otherwise indicated, the function routines listed here are not intrinsics. That means that the type of data a function returns may conflict with the implicit typing of the function name, and require explicit type declaration by the user. For example, getpid() returns INTEGER*4 and would require an INTEGER*4 getpid declaration to ensure proper handling of the result. (Without explicit typing, a REAL result would be assumed by default because the function name starts with g.) As a reminder, explicit type statements appear in the function summaries for these routines.

Be aware that IMPLICIT statements and the -dbl and -xtypemap compiler options also alter the data typing of arguments and the treatment of return values. A mismatch between the expected and actual data types in calls to these library routines could cause unexpected behavior. Options -xtypemap and -dbl promote the data type of INTEGER functions to INTEGER*8, REAL functions to REAL*8, and DOUBLE functions to REAL*16. To protect against these problems, function names and variables appearing in library calls should be explicitly typed with their expected sizes, as in:

        integer*4 seed, getuid
        real*4 ran
        seed = 70198
        val = getuid() + ran(seed)

Explicit typing in the example protects the library calls from any data type promotion when the -xtypemap and -dbl compiler options are used. Without explicit typing, these options could produce unexpected results. See the Fortran User’s Guide and the f95(1) man page for details on these options.

The Fortran 95 compiler, f95, provides an include file,, that defines the interfaces for most non-intrinsic library routines. Include this file to insure that functions you call and their arguments are properly typed, especially when default data types are changed with -xtypemap.

        include ’’
        integer(4) mypid
        mypid = getpid()
        print *, mypid

You can catch many issues related to type mismatches over library calls by using the Fortran compilers’ global program checking option, -Xlist. Global program checking by the f95 compiler is described in the Fortran User’s Guide, the Fortran Programming Guide, and the f95(1) man page.