Fortran User's Guide HomeContentsPreviousNextIndex

Appendix C

Fortran 95 Features and Differences

This appendix shows some of the major features differences between:

Features and Extensions

Sun WorkShop 6 Fortran 95 provides the following features.

Continuation Line Limits

f95 and f77 allow 99 continuation lines (1 initial and 98 continuation lines). Standard Fortran 95 allows 19 for fixed-form and 39 for free-form.

Fixed-Form Source Lines

In fixed-form source, lines can be longer than 72 characters, but everything beyond column 73 is ignored. Standard Fortran 95 only allows 72-character lines.


f95 allows directive lines starting with CDIR$, !DIR$, CMIC$, C$PRAGMA, C$OMP, or !MIC$. For a summary of directives, see Appendix E. Standard Fortran 95 does not consider directives.

Tab Form

The tab form of f95 fixed-format source text is defined as follows:

Example: The tab form source on the left is treated as shown on the right.

!^IUses of tabs
^IREAL C = 3.0
^IWRITE(*,9) A, B, C
^I1 I3,
^I2 F9.1 )
!       Uses of tabs
        CHARACTER *3 A = 'A'
        INTEGER B = 2
        REAL C = 3.0
        WRITE(*,9) A, B, C
9       FORMAT(1X, A3,
       1 I3,
       2 F9.1 )

In the example above, "^I" is a way of indicating the tab character, and the line starting with "1" and "2" are continuation lines. The coding is shown to illustrate various tab situations, and not to advocate any one style.

Source Form Assumed

The source form assumed by f95 depends on options, directives, and suffixes.

TABLE C-1   F95 Source Form Command-line options
Option Action
Interpret all source files as Fortran fixed form
Interpret all source files as Fortran free form

If the -free or -fixed option is used, it overrides the file name suffix. If either a FREE or FIXED directive is used, it overrides the option and file name suffix.

Mixing Forms

Some mixing of source forms is allowed.


Sun Fortran 95 is case insensitive by default. That means that a variable AbcDeF is treated as if it were spelled abcdef. Compile with the -U option to have the compiler treat upper and lower case as unique.

Known Limits

A single Fortran 95 program unit can define up to 65,535 derived types and 16,777,215 distinct constants.

Boolean Type

f95 supports constants and expressions of Boolean type. There are no Boolean variables or arrays, and there is no Boolean type statement.

Miscellaneous Rules Governing Boolean Type

Alternate Forms of Boolean Constants

f95 allows a Boolean constant (octal, hexadecimal, or Hollerith) in the following alternate forms (no binary). Variables cannot be declared Boolean. Standard Fortran does not allow these forms.


ddddddB, where d is any octal digit

Within an I/O format specification, the letter B indicates binary digits; elsewhere it indicates octal digits.


X'ddd' or X"ddd", where d is any hexadecimal digit


Accepted forms for Hollerith data are:

nH... '...'H "..."H
nL... '...'L "..."L
nR... '...'R "..."R

Above, "..." is a string of characters and n is the character count.

Examples: Octal and hexadecimal constants.

Boolean Constant Internal Octal for 32-bit word
X'1 2 3'

Examples: Octal and hexadecimal in assignment statements.

i = 1357B
j = X"28FF"
k = X'-5A'

Use of an octal or hexadecimal constant in an arithmetic expression can produce undefined results and do not generate syntax errors.

Alternate Contexts of Boolean Constants

f95 allows BOZ constants in the places other than DATA statements.

B'bbb' O'ooo' Z'zzz'
B"bbb" O"ooo" Z"zzz"

If these are assigned to a real variable, no type conversion occurs.

Standard Fortran allows these only in DATA statements.

Abbreviated Size Notation for Numeric Data Types

f95 allows the following nonstandard type declaration forms in declaration statements, function statements, and IMPLICIT statements.

TABLE C-2   Size Notation for Numeric Data Types  
Nonstandard Declarator Short Form Meaning
One-byte signed integers
Two-byte signed integers
Four-byte signed integers
One-byte logicals
Two-byte logicals
Four-byte logicals
IEEE single-precision floating-point (Four-byte)
IEEE double-precision floating-point (Eight-byte)
IEEE quad-precision floating-point (Sixteen-byte)
Single-precision complex (Four-bytes each part)
Double-precision complex (Eight-bytes each part)
Quad-precision complex (Sixteen-bytes each part)

The form in column one is nonstandard Fortran 95, though in common use. The kind numbers in column two can vary by vendor.

Cray Pointers

A Cray pointer is a variable whose value is the address of another entity, which is called the pointee.

f95 supports Cray pointers; Standard Fortran 95 does not.


The Cray POINTER statement has the following format:

POINTER  ( pointer_name, pointee_name [array_spec] ), ...

Where pointer_name, pointee_name, and array_spec are as follows:

Pointer to the corresponding pointee_name. pointer_name contains the address of pointee_name. Must be: a scalar variable name (but not a derived type) Cannot be: a constant, a name of a structure, an array, or a function
Pointee of the corresponding pointer_name Must be: a variable name, array declarator, or array name
If array_spec is present, it must be explicit shape, (constant or non-constant bounds), or assumed-size.

Example: Declare Cray pointers to two pointees.

	 POINTER ( p, b ),  ( q, c )

The above example declares Cray pointer p and its pointee b, and Cray pointer q and its pointee c.

Example: Declare a Cray pointer to an array.

	  POINTER ( ix, x(n, 0:m) )

The above example declares Cray pointer ix and its pointee x; and declares x to be an array of dimensions n by m-1.

Purpose of Cray Pointers

You can use pointers to access user-managed storage by dynamically associating variables to particular locations in a block of storage.

Cray pointers allow accessing absolute memory locations.

Cray pointers do not provide convenient manipulation of linked lists because (for optimization purposes) it is assumed that no two pointers have the same value.

Cray Pointers and Fortran Pointers

Cray pointers are declared as follows:

POINTER ( pointer_name, pointee_name [array_spec] )

Fortran pointers are declared as follows:

POINTER object_name

The two kinds of pointers cannot be mixed.

Features of Cray Pointers

Its array declarator can appear in:

  • A separate type statement
  • A separate DIMENSION statement
  • The pointer statement itself

Restrictions on Cray Pointers

Restrictions on Cray Pointees

Usage of Cray Pointers

Cray pointers can be assigned values as follows:

Example: q = 0
Example: p = q + 100
Example: p = LOC( x )

Example: Use Cray pointers as described above.

	 SUBROUTINE  sub ( n )
	 COMMON pool(100000)
	 INTEGER blk(128), word64
	 REAL a(1000), b(n), c(100000-n-1000)
	 POINTER ( pblk, blk ), (ia, a ), ( ib, b ), &
	 	 	 ( ic, c ), ( address, word64 )
	 DATA address / 64 /
	 pblk = 0
	 ia = LOC( pool )
	 ib = ia + 4000
	 ic = ib + n

Remarks about the above example:

Optimization and Cray Pointers

For purposes of optimization, f95 assumes the storage of a pointee is never overlaid on the storage of another variable--it assumes that a pointee is not associated with another variable.

Such association could occur in either of two ways:

These kinds of association are sometimes done deliberately, as in array equivalencing, but then results can differ depending on whether optimization is turned on or off.

Example: b and c have the same pointer.

	 POINTER ( p, b ),  ( p, c )
	 REAL x, b, c
	 p = LOC( x )
	 b = 1.0
	 c = 2.0
	 PRINT *, b

Above, because b and c have the same pointer, assigning 2.0 to c gives the same value to b. Therefore b prints out as 2.0, even though it was assigned 1.0.


f95 supports some intrinsic procedures which are extensions beyond the standard.

TABLE C-3   Nonstandard Intrinsics  
Name Definition Function Type Argument Types Arguments Notes
Cotangent real real
P, E
Positive difference double precision double precision
P, E
Get the number of leading 0 bits integer Boolean, integer, real, or pointer
Get the number of set bits integer Boolean, integer, real, or pointer
Calculate bit population parity integer Boolean, integer, real, or pointer

Notes on the above table:
P The name can be passed as an argument.
NP The name cannot be passed as an argument.
E External code for the intrinsic is called at run time.
I f95 generates inline code for the intrinsic procedure.

I/O Extensions

Some I/O extensions that appear in Sun Fortran 77 have been added to the Fortran 95 compiler:


A compiler directive directs the compiler to do some special action. Directives are also called pragmas.

A compiler directive is inserted into the source program as one or more lines of text. Each line looks like a comment, but has additional characters that identify it as more than a comment for this compiler. For most other compilers, it is treated as a comment, so there is some code portability.

Sun-style directives are the default with f95 (and f77). To switch to Cray-style directives, use the -mp=cray compiler command-line flag.

A complete summary of Fortran directives appears in Appendix E.

Form of Special f95 Directive Lines

f95 recognizes its own special directives in addition to the general f95/f77 directives described in Chapter 2. These have the following syntax:

!DIR$ d1, d2, ...

Fixed-Form Source

Free-Form Source

Thus, !DIR$ in columns 1 through 5 works for both free-form source and fixed-form source.

FIXED and FREE Directives

These directives specify the source form of lines following the directive line.


They apply to the rest of the file in which they appear, or until the next FREE or FIXED directive is encountered.



The FREE/FIXED directives:

Example: A FREE directive.

	 DO i = 1, n
	 	 a(i) = b(i) * c(i)

Parallelization Directives

A parallelization directive is a special comment that directs the compiler to attempt to parallelize the next DO loop. These are summarized in Appendix E and described in the Fortran Programming Guide. f95 recognizes both f77 Sun and Cray style parallelization directives, as well as the OpenMP Fortran API directives.

Note – Fortran parallelization features require a Sun WorkShop HPC license.

Compatibility with FORTRAN 77


Standard-conforming, fixed-format (filename.f) FORTRAN 77 source code is compatible with Sun Fortran 95. Use of non-standard extensions, such as VMS Fortran features, are not compatible and may not compile with Sun Fortran 95.


The f77 compiler allows up to 20 array subscripts while f90 only allows 7.

Linking with f77-Compiled Routines

f95 ..files.. -lf77compat
Example: f95 main and f77 subroutine.

demo% cat m.f95
CHARACTER*74 :: c = 'This is a test.'
   CALL echo1( c )
demo$ cat s.f
       SUBROUTINE echo1( a )
       CHARACTER*74 a
       PRINT*, a
demo% f77 -c -silent s.f
demo% f95 m.f95 s.o -lf77compat
demo% a.out
 This is a test.

Example: f95 main calls a routine from the FORTRAN 77 library.

demo% cat tdtime.f95
        REAL e, dtime, t(2)
        e = dtime( t )
        DO i = 1, 100000
           as = as + cos(sqrt(float(i)))
        END DO
        e = dtime( t )
        PRINT *, 'elapsed:', e, ', user:', t(1), ', sys:', t(2)
demo% f95 tdtime.f95
demo% a.out
elapsed: 0.14 , user: 0.14 , sys: 0.0E+0

See dtime(3F).


f77 and f95 are generally I/O compatible for binary I/O, since f95 links to the f77 compatibility library.

Such compatibility includes the following two situations:

The numbers read back in may or may not equal the numbers written out.


The Fortran 95 standard supports the following new intrinsic functions that FORTRAN 77 does not have.

If you use one of these names in your program, you must add an EXTERNAL statement to make f95 use your function rather than the intrinsic one.

Fortran 95 intrinsics:


Forward Compatibility

Future releases of f95 are intended to be source code compatible with this release.

Module information files generated by this release of f95 are not guaranteed to be compatible with future releases.

Mixing Languages

On Solaris systems, routines written in C can be combined with Fortran programs, since these languages have common calling conventions.

Module Files

Compiling a file containing a Fortran 95 MODULE generates a module file (.mod file) for every MODULE encountered in the source. The file name is derived from the name of the MODULE; file xyz.mod (all lowercase) will be created for MODULE xyz.

By default, such files are usually sought in the current working directory. The -Mdir option allows you to tell f95 to seek them in an additional location.

The .mod files cannot be stored into an archive file, or concatenated into a single file.

Sun Microsystems, Inc.
Copyright information. All rights reserved.
Library   |   Contents   |   Previous   |   Next   |   Index