     [file gcc-common.texi not included]

This file documents the use and the internals of the GNU Fortran compiler, (gfortran).

Published by the Free Software Foundation 51 Franklin Street, Fifth Floor Boston, MA 02110-1301 USA

Copyright © 1999-2006 Free Software Foundation, Inc.

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.1 or any later version published by the Free Software Foundation; with the Invariant Sections being ``GNU General Public License'' and ``Funding Free Software'', the Front-Cover texts being (a) (see below), and with the Back-Cover Texts being (b) (see below).  A copy of the license is included in the section entitled ``GNU Free Documentation License''.

(a) The FSF's Front-Cover Text is:

A GNU Manual

(b) The FSF's Back-Cover Text is:

You have freedom to copy and modify this GNU Manual, like GNU software.  Copies published by the Free Software Foundation raise funds for GNU development.

Introduction
************

This manual documents the use of gfortran, the GNU Fortran compiler. You can find in this manual how to invoke gfortran, as well as its features and incompatibilities.

Introduction
************

The GNU Fortran compiler front end was designed initially as a free replacement for, or alternative to, the unix f95 command; gfortran is the command you'll use to invoke the compiler.

About GNU Fortran
=================

The GNU Fortran compiler is still in an early state of development. It can generate code for most constructs and expressions, but much work remains to be done.

When the GNU Fortran compiler is finished, it will do everything you expect from any decent compiler:

  * Read a user's program, stored in a file and containing instructions written in Fortran 77, Fortran 90, Fortran 95 or Fortran 2003. This file contains source code.

  * Translate the user's program into instructions a computer can carry out more quickly than it takes to translate the instructions in the first place.  The result after compilation of a program is machine code, code designed to be efficiently translated and processed by a machine such as your computer. Humans usually aren't as good writing machine code as they are at writing Fortran (or C++, Ada, or Java), because is easy to make tiny mistakes writing machine code.

  * Provide the user with information about the reasons why the compiler is unable to create a binary from the source code. Usually this will be the case if the source code is flawed. When writing Fortran, it is easy to make big mistakes. The Fortran 90 requires that the compiler can point out mistakes to the user. An incorrect usage of the language causes an error message.

     The compiler will also attempt to diagnose cases where the user's program contains a correct usage of the language, but instructs the computer to do something questionable. This kind of diagnostics message is called a warning message.

  * Provide optional information about the translation passes from the source code to machine code. This can help a user of the compiler to find the cause of certain bugs which may not be obvious in the source code, but may be more easily found at a lower level compiler output. It also helps developers to find bugs in the compiler itself.

  * Provide information in the generated machine code that can make it easier to find bugs in the program (using a debugging tool, called a debugger, such as the GNU Debugger gdb).

  * Locate and gather machine code already generated to perform actions requested by statements in the user's program. This machine code is organized into modules and is located and linked to the user program.

The GNU Fortran compiler consists of several components:

  * A version of the gcc command (which also might be installed as the system's cc command) that also understands and accepts Fortran source code. The gcc command is the driver program for all the languages in the GNU Compiler Collection (GCC); With gcc, you can compile the source code of any language for which a front end is available in GCC.

  * The gfortran command itself, which also might be installed as the system's f95 command. gfortran is just another driver program, but specifically for the Fortran compiler only. The difference with gcc is that gfortran will automatically link the correct libraries to your program.

  * A collection of run-time libraries. These libraries contain the machine code needed to support capabilities of the Fortran language that are not directly provided by the machine code generated by the gfortran compilation phase, such as intrinsic functions and subroutines, and routines for interaction with files and the operating system.

  * The Fortran compiler itself, (f951). This is the GNU Fortran parser and code generator, linked to and interfaced with the GCC backend library. f951 ``translates'' the source code to assembler code.  You would typically not use this program directly; instead, the gcc or gfortran driver programs will call it for you.

GNU Fortran and GCC
===================

GCC used to be the GNU ``C'' Compiler, but is now known as the GNU Compiler Collection. GCC provides the GNU system with a very versatile compiler middle end (shared optimization passes), and back ends (code generators) for many different computer architectures and operating systems. The code of the middle end and back end are shared by all compiler front ends that are in the GNU Compiler Collection.

A GCC front end is essentially a source code parser and an intermediate code generator.  The code generator translates the semantics of the source code into a language independent form called GENERIC.

The parser takes a source file written in a particular computer language, reads and parses it, and tries to make sure that the source code conforms to the language rules. Once the correctness of a program has been established, the compiler will build a data structure known as the Abstract Syntax tree, or just AST or ``tree'' for short. This data structure represents the whole program or a subroutine or a function. The ``tree'' is passed to the GCC middle end, which will perform optimization passes on it.  The optimized AST is then handed off too the back end which assembles the program unit.

Different phases in this translation process can be, and in fact are merged in many compiler front ends. GNU Fortran has a strict separation between the parser and code generator.

The goal of the GNU Fortran project is to build a new front end for GCC. Specifically, a Fortran 95 front end. In a non-gfortran installation, gcc will not be able to compile Fortran source code (only the ``C'' front end has to be compiled if you want to build GCC, all other languages are optional). If you build GCC with gfortran, gcc will recognize .f/.f90/.f95 source files and accepts Fortran specific command line options.

GNU Fortran and G77
===================

Why do we write a compiler front end from scratch? There's a fine Fortran 77 compiler in the GNU Compiler Collection that accepts some features of the Fortran 90 standard as extensions. Why not start from there and revamp it?

One of the reasons is that Craig Burley, the author of G77, has decided to stop working on the G77 front end. On Craig explains the reasons for his decision to stop working on G77 (http://world.std.com/~burley/g77-why.html) in one of the pages in his homepage. Among the reasons is a lack of interest in improvements to g77. Users appear to be quite satisfied with g77 as it is. While g77 is still being maintained (by Toon Moene), it is unlikely that sufficient people will be willing to completely rewrite the existing code.

But there are other reasons to start from scratch. Many people, including Craig Burley, no longer agreed with certain design decisions in the G77 front end. Also, the interface of g77 to the back end is written in a style which is confusing and not up to date on recommended practice. In fact, a full rewrite had already been planned for GCC 3.0.

When Craig decided to stop, it just seemed to be a better idea to start a new project from scratch, because it was expected to be easier to maintain code we develop ourselves than to do a major overhaul of g77 first, and then build a Fortran 95 compiler out of it.

Project Status
==============

     As soon as gfortran can parse all of the statements correctly, it will be in the ``larva'' state. When we generate code, the ``puppa'' state. When gfortran is done, we'll see if it will be a beautiful butterfly, or just a big bug....

     --Andy Vaught, April 2000

The start of the GNU Fortran 95 project was announced on the GCC homepage in March 18, 2000 (even though Andy had already been working on it for a while, of course).

The GNU Fortran compiler is able to compile nearly all standard-compliant Fortran 95, Fortran 90, and Fortran 77 programs, including a number of standard and non-standard extensions, and can be used on real-world programs.  In particular, the supported extensions include OpenMP, Cray-style pointers, and several Fortran 2003 features such as enumeration, stream I/O, and some of the enhancements to allocatable array support from TR 15581.  However, it is still under development and has a few remaining rough edges.

At present, the GNU Fortran compiler passes the NIST Fortran 77 Test Suite (http://www.fortran-2000.com/ArnaudRecipes/fcvs21_f95.html), and produces acceptable results on the LAPACK Test Suite (http://www.netlib.org/lapack/faq.html#1.21). It also provides respectable performance on the Polyhedron Fortran compiler benchmarks (http://www.polyhedron.com/pb05.html) and the Livermore Fortran Kernels test (http://www.llnl.gov/asci_benchmarks/asci/limited/lfk/README.html).  It has been used to compile a number of large real-world programs, including the HIRLAM weather-forecasting code (http://mysite.verizon.net/serveall/moene.pdf) and the Tonto quantum chemistry package (http://www.theochem.uwa.edu.au/tonto/); see http://gcc.gnu.org/wiki/GfortranApps for an extended list.

Among other things, the GNU Fortran compiler is intended as a replacement for G77.  At this point, nearly all programs that could be compiled with G77 can be compiled with GNU Fortran, although there are a few minor known regressions.

The primary work remaining to be done on GNU Fortran falls into three categories: bug fixing (primarily regarding the treatment of invalid code and providing useful error messages), improving the compiler optimizations and the performance of compiled code, and extending the compiler to support future standards---in particular, Fortran 2003.

Standards
=========

The GNU Fortran compiler implements ISO/IEC 1539:1997 (Fortran 95).  As such, it can also compile essentially all standard-compliant Fortran 90 and Fortran 77 programs.   It also supports the ISO/IEC TR-15581 enhancements to allocatable arrays, and the OpenMP Application Program Interface v2.5 (http://www.openmp.org/drupal/mp-documents/spec25.pdf) specification.

In the future, the GNU Fortran compiler may also support other standard variants of and extensions to the Fortran language.  These include ISO/IEC 1539-1:2004 (Fortran 2003).

     [file invoke.texi not included]

Runtime: Influencing runtime behavior with environment variables
****************************************************************

The behavior of the gfortran can be influenced by environment variables.

Malformed environment variables are silently ignored.

GFORTRAN_STDIN_UNIT---Unit number for standard input
====================================================

This environment variable can be used to select the unit number preconnected to standard input.  This must be a positive integer. The default value is 5.

GFORTRAN_STDOUT_UNIT---Unit number for standard output
======================================================

This environment variable can be used to select the unit number preconnected to standard output.  This must be a positive integer. The default value is 6.

GFORTRAN_STDERR_UNIT---Unit number for standard error
=====================================================

This environment variable can be used to select the unit number preconnected to standard error.  This must be a positive integer. The default value is 0.

GFORTRAN_USE_STDERR---Send library output to standard error
===========================================================

This environment variable controls where library output is sent. If the first letter is y, Y or 1, standard error is used. If the first letter is n, N or 0, standard output is used.

GFORTRAN_TMPDIR---Directory for scratch files
=============================================

This environment variable controls where scratch files are created.  If this environment variable is missing, GNU Fortran searches for the environment variable TMP.  If this is also missing, the default is /tmp.

GFORTRAN_UNBUFFERED_ALL---Don't buffer output
=============================================

This environment variable controls whether all output is unbuffered. If the first letter is y, Y or 1, all output is unbuffered. This will slow down large writes.  If the first letter is n, N  or 0, output is buffered.  This is the default.

GFORTRAN_SHOW_LOCUS---Show location for runtime errors
======================================================

If the first letter is y, Y or 1, filename and line numbers for runtime errors are printed.  If the first letter is n, N or 0, don't print filename and line numbers for runtime errors. The default is to print the location.

GFORTRAN_OPTIONAL_PLUS---Print leading + where permitted
========================================================

If the first letter is y, Y or 1, a plus sign is printed where permitted by the Fortran standard.  If the first letter is n, N or 0, a plus sign is not printed in most cases. Default is not to print plus signs.

GFORTRAN_DEFAULT_RECL---Default record length for new files
===========================================================

This environment variable specifies the default record length, in bytes, for files which are opened without a RECL tag in the OPEN statement.  This must be a positive integer.  The default value is 1073741824 bytes (1 GB).

GFORTRAN_LIST_SEPARATOR---Separator for list output
===================================================

This environment variable specifies the separator when writing list-directed output.  It may contain any number of spaces and at most one comma.  If you specify this on the command line, be sure to quote spaces, as in

     $ GFORTRAN_LIST_SEPARATOR='  ,  ' ./a.out

when a.out is the compiled Fortran program that you want to run. Default is a single space.

GFORTRAN_CONVERT_UNIT---Set endianness for unformatted I/O
==========================================================

By setting the GFORTRAN_CONVERT_UNIT variable, it is possible to change the representation of data for unformatted files. The syntax for the GFORTRAN_CONVERT_UNIT variable is:

     GFORTRAN_CONVERT_UNIT: mode | mode ';' exception ;
     mode: 'native' | 'swap' | 'big_endian' | 'little_endian' ;
     exception: mode ':' unit_list | unit_list ;
     unit_list: unit_spec | unit_list unit_spec ;
     unit_spec: INTEGER | INTEGER '-' INTEGER ;

The variable consists of an optional default mode, followed by a list of optional exceptions, which are separated by semicolons from the preceding default and each other.  Each exception consists of a format and a comma-separated list of units.  Valid values for the modes are the same as for the CONVERT specifier:

  NATIVE Use the native format.  This is the default.

  SWAP Swap between little- and big-endian.

  LITTLE_ENDIAN Use the little-endian format for unformatted files.

  BIG_ENDIAN Use the big-endian format for unformatted files.

A missing mode for an exception is taken to mean BIG_ENDIAN. Examples of values for GFORTRAN_CONVERT_UNIT are:

  'big_endian'  Do all unformatted I/O in big_endian mode.

  'little_endian;native:10-20,25'  Do all unformatted I/O in little_endian mode, except for units 10 to 20 and 25, which are in native format.

  '10-20'  Units 10 to 20 are big-endian, the rest is native.

Setting the environment variables should be done on the command line or via the export command for sh-compatible shells and via setenv for csh-compatible shells.

Example for sh:

     $ gfortran foo.f90
     $ GFORTRAN_CONVERT_UNIT='big_endian;native:10-20' ./a.out

Example code for csh:

     % gfortran foo.f90
     % setenv GFORTRAN_CONVERT_UNIT 'big_endian;native:10-20'
     % ./a.out

Using anything but the native representation for unformatted data carries a significant speed overhead.  If speed in this area matters to you, it is best if you use this only for data that needs to be portable.

See CONVERT specifier, for an alternative way to specify the data representation for unformatted files.  See Runtime Options, for setting a default data representation for the whole program.  The CONVERT specifier overrides the -fconvert compile options.

Fortran 2003 Status
*******************

Although GNU Fortran focuses on implementing the Fortran 95 standard for the time being, a few Fortran 2003 features are currently available.

  * Intrinsics command_argument_count, get_command, get_command_argument, get_environment_variable, and move_alloc.

  * Array constructors using square brackets. That is, [...] rather than (/.../).

  * FLUSH statement.

  * IOMSG= specifier for I/O statements.

  * Support for the declaration of enumeration constants via the ENUM and ENUMERATOR statements.  Interoperability with gcc is guaranteed also for the case where the -fshort-enums command line option is given.

  * TR 15581:

       * ALLOCATABLE dummy arguments.

       * ALLOCATABLE function results

       * ALLOCATABLE components of derived types

  * The OPEN statement supports the ACCESS='STREAM' specifier, allowing I/O without any record structure.

  * Namelist input/output for internal files.

  * The PROTECTED statement and attribute.

  * The VALUE statement and attribute.

  * The VOLATILE statement and attribute.

  * The IMPORT statement, allowing to import host-associated derived types.

  * USE statement with INTRINSIC and NON_INTRINSIC attribute; supported intrinsic modules: ISO_FORTRAN_ENV, OMP_LIB and OMP_LIB_KINDS.

Extensions
**********

GNU Fortran implements a number of extensions over standard Fortran. This chapter contains information on their syntax and meaning.  There are currently two categories of GNU Fortran extensions, those that provide functionality beyond that provided by any standard, and those that are supported by GNU Fortran purely for backward compatibility with legacy compilers.  By default, -std=gnu allows the compiler to accept both types of extensions, but to warn about the use of the latter.  Specifying either -std=f95 or -std=f2003 disables both types of extensions, and -std=legacy allows both without warning.

Old-style kind specifications
=============================

GNU Fortran allows old-style kind specifications in declarations. These look like:

           TYPESPEC*k x,y,z

where TYPESPEC is a basic type (INTEGER, REAL, etc.), and where k is a valid kind number for that type. The statement then declares x, y and z to be of type TYPESPEC with kind k. This is equivalent to the standard conforming declaration

           TYPESPEC(k) x,y,z

Old-style variable initialization
=================================

GNU Fortran allows old-style initialization of variables of the form:

           INTEGER i/1/,j/2/
           REAL x(2,2) /3*0.,1./

The syntax for the initializers is as for the DATA statement, but unlike in a DATA statement, an initializer only applies to the variable immediately preceding the initialization.  In other words, something like INTEGER I,J/2,3/ is not valid.  This style of initialization is only allowed in declarations without double colons (::); the double colons were introduced in Fortran 90, which also introduced a standard syntax for initializating variables in type declarations.

Examples of standard-conforming code equivalent to the above example are:

     ! Fortran 90
           INTEGER :: i = 1, j = 2
           REAL :: x(2,2) = RESHAPE((/0.,0.,0.,1./),SHAPE(x))
     ! Fortran 77
           INTEGER i, j
           REAL x(2,2)
           DATA i/1/, j/2/, x/3*0.,1./

Note that variables which are explicitly initialized in declarations or in DATA statements automatically acquire the SAVE attribute.

Extensions to namelist
======================

GNU Fortran fully supports the Fortran 95 standard for namelist I/O including array qualifiers, substrings and fully qualified derived types. The output from a namelist write is compatible with namelist read.  The output has all names in upper case and indentation to column 1 after the namelist name.  Two extensions are permitted:

Old-style use of $ instead of &

     $MYNML
      X(:)%Y(2) = 1.0 2.0 3.0
      CH(1:4) = "abcd"
     $END

It should be noted that the default terminator is / rather than &END.

Querying of the namelist when inputting from stdin. After at least one space, entering ? sends to stdout the namelist name and the names of the variables in the namelist:

      ?

     &mynml
      x
      x%y
      ch
     &end

Entering =? outputs the namelist to stdout, as if WRITE(*,NML = mynml) had been called:

     =?

     &MYNML
      X(1)%Y=  0.000000    ,  1.000000    ,  0.000000    ,
      X(2)%Y=  0.000000    ,  2.000000    ,  0.000000    ,
      X(3)%Y=  0.000000    ,  3.000000    ,  0.000000    ,
      CH=abcd,  /

To aid this dialog, when input is from stdin, errors send their messages to stderr and execution continues, even if IOSTAT is set.

PRINT namelist is permitted.  This causes an error if -std=f95 is used.

     PROGRAM test_print
       REAL, dimension (4)  ::  x = (/1.0, 2.0, 3.0, 4.0/)
       NAMELIST /mynml/ x
       PRINT mynml
     END PROGRAM test_print

Expanded namelist reads are permitted.  This causes an error if -std=f95 is used.  In the following example, the first element of the array will be given the value 0.00 and the two succeeding elements will be given the values 1.00 and 2.00.

     &MYNML
       X(1,1) = 0.00 , 1.00 , 2.00
     /

X format descriptor without count field
=======================================

To support legacy codes, GNU Fortran permits the count field of the X edit descriptor in FORMAT statements to be omitted. When omitted, the count is implicitly assumed to be one.

            PRINT 10, 2, 3
     10     FORMAT (I1, X, I1)

Commas in FORMAT specifications
===============================

To support legacy codes, GNU Fortran allows the comma separator to be omitted immediately before and after character string edit descriptors in FORMAT statements.

            PRINT 10, 2, 3
     10     FORMAT ('FOO='I1' BAR='I2)

Missing period in FORMAT specifications
=======================================

To support legacy codes, GNU Fortran allows missing periods in format specifications if and only if -std=legacy is given on the command line.  This is considered non-conforming code and is discouraged.

            REAL :: value
            READ(*,10) value
     10     FORMAT ('F4')

I/O item lists
==============

To support legacy codes, GNU Fortran allows the input item list of the READ statement, and the output item lists of the WRITE and PRINT statements, to start with a comma.

BOZ literal constants
=====================

As an extension, GNU Fortran allows hexadecimal BOZ literal constants to be specified using the X prefix, in addition to the standard Z prefix. BOZ literal constants can also be specified by adding a suffix to the string. For example, Z'ABC' and 'ABC'Z are equivalent.

The Fortran standard restricts the appearance of a BOZ literal constant to the DATA statement, and it is expected to be assigned to an INTEGER variable.  GNU Fortran permits a BOZ literal to appear in any initialization expression as well as assignment statements.

Attempts to use a BOZ literal constant to do a bitwise initialization of a variable can lead to confusion.  A BOZ literal constant is converted to an INTEGER value with the kind type with the largest decimal representation, and this value is then converted numerically to the type and kind of the variable in question.  Thus, one should not expect a bitwise copy of the BOZ literal constant to be assigned to a REAL variable.

Similarly, initializing an INTEGER variable with a statement such as DATA i/Z'FFFFFFFF'/ will produce an integer overflow rather than the desired result of -1 when i is a 32-bit integer on a system that supports 64-bit integers.  The -fno-range-check option can be used as a workaround for legacy code that initializes integers in this manner.

Real array indices
==================

As an extension, GNU Fortran allows the use of REAL expressions or variables as array indices.

Unary operators
===============

As an extension, GNU Fortran allows unary plus and unary minus operators to appear as the second operand of binary arithmetic operators without the need for parenthesis.

            X = Y * -Z

Implicitly convert LOGICAL and INTEGER values
=============================================

As an extension for backwards compatibility with other compilers, GNU Fortran allows the implicit conversion of LOGICAL values to INTEGER values and vice versa.  When converting from a LOGICAL to an INTEGER, .FALSE. is interpreted as zero, and .TRUE. is interpreted as one.  When converting from INTEGER to LOGICAL, the value zero is interpreted as .FALSE. and any nonzero value is interpreted as .TRUE..

            INTEGER :: i = 1
            IF (i) PRINT *, 'True'

Hollerith constants support
===========================

GNU Fortran supports Hollerith constants in assignments, function arguments, and DATA and ASSIGN statements.  A Hollerith constant is written as a string of characters preceeded by an integer constant indicating the character count, and the letter H or h, and stored in bytewise fashion in a numeric (INTEGER, REAL, or complex) or LOGICAL variable.  The constant will be padded or truncated to fit the size of the variable in which it is stored.

Examples of valid uses of Hollerith constants:

           complex*16 x(2)
           data x /16Habcdefghijklmnop, 16Hqrstuvwxyz012345/
           x(1) = 16HABCDEFGHIJKLMNOP
           call foo (4h abc)

Invalid Hollerith constants examples:

           integer*4 a
           a = 8H12345678 ! Valid, but the Hollerith constant will be truncated.
           a = 0H         ! At least one character is needed.

In general, Hollerith constants were used to provide a rudimentary facility for handling character strings in early Fortran compilers, prior to the introduction of CHARACTER variables in Fortran 77; in those cases, the standard-compliant equivalent is to convert the program to use proper character strings.  On occasion, there may be a case where the intent is specifically to initialize a numeric variable with a given byte sequence.  In these cases, the same result can be obtained by using the TRANSFER statement, as in this example.

           INTEGER(KIND=4) :: a
           a = TRANSFER ("abcd", a)     ! equivalent to: a = 4Habcd

Cray pointers
=============

Cray pointers are part of a non-standard extension that provides a C-like pointer in Fortran.  This is accomplished through a pair of variables: an integer "pointer" that holds a memory address, and a "pointee" that is used to dereference the pointer.

Pointer/pointee pairs are declared in statements of the form:

             pointer ( <pointer> , <pointee> )

or,

             pointer ( <pointer1> , <pointee1> ), ( <pointer2> , <pointee2> ), ...

The pointer is an integer that is intended to hold a memory address. The pointee may be an array or scalar.  A pointee can be an assumed size array---that is, the last dimension may be left unspecified by using a * in place of a value---but a pointee cannot be an assumed shape array.  No space is allocated for the pointee.

The pointee may have its type declared before or after the pointer statement, and its array specification (if any) may be declared before, during, or after the pointer statement.  The pointer may be declared as an integer prior to the pointer statement.  However, some machines have default integer sizes that are different than the size of a pointer, and so the following code is not portable:

             integer ipt
             pointer (ipt, iarr)

If a pointer is declared with a kind that is too small, the compiler will issue a warning; the resulting binary will probably not work correctly, because the memory addresses stored in the pointers may be truncated.  It is safer to omit the first line of the above example; if explicit declaration of ipt's type is omitted, then the compiler will ensure that ipt is an integer variable large enough to hold a pointer.

Pointer arithmetic is valid with Cray pointers, but it is not the same as C pointer arithmetic.  Cray pointers are just ordinary integers, so the user is responsible for determining how many bytes to add to a pointer in order to increment it.  Consider the following example:

             real target(10)
             real pointee(10)
             pointer (ipt, pointee)
             ipt = loc (target)
             ipt = ipt + 1

The last statement does not set ipt to the address of target(1), as it would in C pointer arithmetic.  Adding 1 to ipt just adds one byte to the address stored in ipt.

Any expression involving the pointee will be translated to use the value stored in the pointer as the base address.

To get the address of elements, this extension provides an intrinsic function LOC().  The LOC() function is equivalent to the & operator in C, except the address is cast to an integer type:

             real ar(10)
             pointer(ipt, arpte(10))
             real arpte
             ipt = loc(ar)  ! Makes arpte is an alias for ar
             arpte(1) = 1.0 ! Sets ar(1) to 1.0

The pointer can also be set by a call to the MALLOC intrinsic (see MALLOC).

Cray pointees often are used to alias an existing variable.  For example:

             integer target(10)
             integer iarr(10)
             pointer (ipt, iarr)
             ipt = loc(target)

As long as ipt remains unchanged, iarr is now an alias for target. The optimizer, however, will not detect this aliasing, so it is unsafe to use iarr and target simultaneously.  Using a pointee in any way that violates the Fortran aliasing rules or assumptions is illegal. It is the user's responsibility to avoid doing this; the compiler works under the assumption that no such aliasing occurs.

Cray pointers will work correctly when there is no aliasing (i.e., when they are used to access a dynamically allocated block of memory), and also in any routine where a pointee is used, but any variable with which it shares storage is not used.  Code that violates these rules may not run as the user intends.  This is not a bug in the optimizer; any code that violates the aliasing rules is illegal.  (Note that this is not unique to GNU Fortran; any Fortran compiler that supports Cray pointers will ``incorrectly'' optimize code with illegal aliasing.)

There are a number of restrictions on the attributes that can be applied to Cray pointers and pointees.  Pointees may not have the ALLOCATABLE, INTENT, OPTIONAL, DUMMY, TARGET, INTRINSIC, or POINTER attributes. Pointers may not have the DIMENSION, POINTER, TARGET, ALLOCATABLE, EXTERNAL, or INTRINSIC attributes. Pointees may not occur in more than one pointer statement.  A pointee cannot be a pointer.  Pointees cannot occur in equivalence, common, or data statements.

A Cray pointer may also point to a function or a subroutine.  For example, the following excerpt is valid:

       implicit none
       external sub
       pointer (subptr,subpte)
       external subpte
       subptr = loc(sub)
       call subpte()
       [...]
       subroutine sub
       [...]
       end subroutine sub

A pointer may be modified during the course of a program, and this will change the location to which the pointee refers.  However, when pointees are passed as arguments, they are treated as ordinary variables in the invoked function.  Subsequent changes to the pointer will not change the base address of the array that was passed.

CONVERT specifier
=================

GNU Fortran allows the conversion of unformatted data between little- and big-endian representation to facilitate moving of data between different systems.  The conversion can be indicated with the CONVERT specifier on the OPEN statement. See GFORTRAN_CONVERT_UNIT, for an alternative way of specifying the data format via an environment variable.

Valid values for CONVERT are:

  CONVERT='NATIVE' Use the native format.  This is the default.

  CONVERT='SWAP' Swap between little- and big-endian.

  CONVERT='LITTLE_ENDIAN' Use the little-endian representation for unformatted files.

  CONVERT='BIG_ENDIAN' Use the big-endian representation for unformatted files.

Using the option could look like this:

       open(file='big.dat',form='unformatted',access='sequential', &
            convert='big_endian')

The value of the conversion can be queried by using INQUIRE(CONVERT=ch).  The values returned are 'BIG_ENDIAN' and 'LITTLE_ENDIAN'.

CONVERT works between big- and little-endian for INTEGER values of all supported kinds and for REAL on IEEE systems of kinds 4 and 8.  Conversion between different ``extended double'' types on different architectures such as m68k and x86_64, which GNU Fortran supports as REAL(KIND=10) and REAL(KIND=16), will probably not work.

Note that the values specified via the GFORTRAN_CONVERT_UNIT environment variable will override the CONVERT specifier in the open statement.  This is to give control over data formats to users who do not have the source code of their program available.

Using anything but the native representation for unformatted data carries a significant speed overhead.  If speed in this area matters to you, it is best if you use this only for data that needs to be portable.

OpenMP
======

GNU Fortran attempts to be OpenMP Application Program Interface v2.5 compatible when invoked with the -fopenmp option.  GNU Fortran then generates parallelized code according to the OpenMP directives used in the source.  The OpenMP Fortran runtime library routines are provided both in a form of a Fortran 90 module named omp_lib and in a form of a Fortran include file named omp_lib.h.

For details refer to the actual OpenMP Application Program Interface v2.5 (http://www.openmp.org/drupal/mp-documents/spec25.pdf) specification.

     [file intrinsic.texi not included]

Contributing
************

Free software is only possible if people contribute to efforts to create it. We're always in need of more people helping out with ideas and comments, writing documentation and contributing code.

If you want to contribute to GNU Fortran, have a look at the long lists of projects you can take on. Some of these projects are small, some of them are large; some are completely orthogonal to the rest of what is happening on GNU Fortran, but others are ``mainstream'' projects in need of enthusiastic hackers. All of these projects are important! We'll eventually get around to the things here, but they are also things doable by someone who is willing and able.

Contributors to GNU Fortran
===========================

Most of the parser was hand-crafted by Andy Vaught, who is also the initiator of the whole project.  Thanks Andy! Most of the interface with GCC was written by Paul Brook.

The following individuals have contributed code and/or ideas and significant help to the GNU Fortran project (in no particular order):

  - Andy Vaught

  - Katherine Holcomb

  - Tobias Schlüter

  - Steven Bosscher

  - Toon Moene

  - Tim Prince

  - Niels Kristian Bech Jensen

  - Steven Johnson

  - Paul Brook

  - Feng Wang

  - Bud Davis

  - Paul Thomas

  - François-Xavier Coudert

  - Steven G. Kargl

  - Jerry Delisle

  - Janne Blomqvist

  - Erik Edelmann

  - Thomas Koenig

  - Asher Langton

  - Jakub Jelinek

  - Roger Sayle

  - H.J. Lu

  - Richard Henderson

  - Richard Sandiford

  - Richard Guenther

  - Bernhard Fischer

The following people have contributed bug reports, smaller or larger patches, and much needed feedback and encouragement for the GNU Fortran project:

  - Erik Schnetter

  - Bill Clodius

  - Kate Hedstrom

Many other individuals have helped debug, test and improve the GNU Fortran compiler over the past few years, and we welcome you to do the same! If you already have done so, and you would like to see your name listed in the list above, please contact us.

Projects
========

Help build the test suite
     Solicit more code for donation to the test suite. We can keep code private on request.

Bug hunting/squishing
     Find bugs and write more test cases! Test cases are especially very welcome, because it allows us to concentrate on fixing bugs instead of isolating them.

Smaller projects (``bug'' fixes):

       - Allow init exprs to be numbers raised to integer powers.

       - Implement correct rounding.

       - Implement F restrictions on Fortran 95 syntax.

       - See about making Emacs-parsable error messages.

If you wish to work on the runtime libraries, please contact a project maintainer.

Proposed Extensions
===================

Here's a list of proposed extensions for the GNU Fortran compiler, in no particular order.  Most of these are necessary to be fully compatible with existing Fortran compilers, but they are not part of the official J3 Fortran 95 standard.

Compiler extensions:
--------------------

  * User-specified alignment rules for structures.

  * Flag to generate Makefile info.

  * Automatically extend single precision constants to double.

  * Compile code that conserves memory by dynamically allocating common and module storage either on stack or heap.

  * Compile flag to generate code for array conformance checking (suggest -CC).

  * User control of symbol names (underscores, etc).

  * Compile setting for maximum size of stack frame size before spilling parts to static or heap.

  * Flag to force local variables into static space.

  * Flag to force local variables onto stack.

  * Flag for maximum errors before ending compile.

  * Option to initialize otherwise uninitialized integer and floating point variables.

Environment Options
-------------------

  * Pluggable library modules for random numbers, linear algebra. LA should use BLAS calling conventions.

  * Environment variables controlling actions on arithmetic exceptions like overflow, underflow, precision loss---Generate NaN, abort, default. action.

  * Set precision for fp units that support it (i387).

  * Variable for setting fp rounding mode.

  * Variable to fill uninitialized variables with a user-defined bit pattern.

  * Environment variable controlling filename that is opened for that unit number.

  * Environment variable to clear/trash memory being freed.

  * Environment variable to control tracing of allocations and frees.

  * Environment variable to display allocated memory at normal program end.

  * Environment variable for filename for * IO-unit.

  * Environment variable for temporary file directory.

  * Environment variable forcing standard output to be line buffered (unix).

     [file gpl.texi not included]

     [file fdl.texi not included]

     [file funding.texi not included]