OpenCores
URL https://opencores.org/ocsvn/openrisc_2011-10-31/openrisc_2011-10-31/trunk

Subversion Repositories openrisc_2011-10-31

[/] [openrisc/] [trunk/] [gnu-src/] [gcc-4.5.1/] [gcc/] [fortran/] [gfortran.texi] - Diff between revs 285 and 378

Only display areas with differences | Details | Blame | View Log

Rev 285 Rev 378
\input texinfo  @c -*-texinfo-*-
\input texinfo  @c -*-texinfo-*-
@c %**start of header
@c %**start of header
@setfilename gfortran.info
@setfilename gfortran.info
@set copyrights-gfortran 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
@set copyrights-gfortran 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
 
 
@include gcc-common.texi
@include gcc-common.texi
 
 
@settitle The GNU Fortran Compiler
@settitle The GNU Fortran Compiler
 
 
@c Create a separate index for command line options
@c Create a separate index for command line options
@defcodeindex op
@defcodeindex op
@c Merge the standard indexes into a single one.
@c Merge the standard indexes into a single one.
@syncodeindex fn cp
@syncodeindex fn cp
@syncodeindex vr cp
@syncodeindex vr cp
@syncodeindex ky cp
@syncodeindex ky cp
@syncodeindex pg cp
@syncodeindex pg cp
@syncodeindex tp cp
@syncodeindex tp cp
 
 
@c TODO: The following "Part" definitions are included here temporarily
@c TODO: The following "Part" definitions are included here temporarily
@c until they are incorporated into the official Texinfo distribution.
@c until they are incorporated into the official Texinfo distribution.
@c They borrow heavily from Texinfo's \unnchapentry definitions.
@c They borrow heavily from Texinfo's \unnchapentry definitions.
 
 
@tex
@tex
\gdef\part#1#2{%
\gdef\part#1#2{%
  \pchapsepmacro
  \pchapsepmacro
  \gdef\thischapter{}
  \gdef\thischapter{}
  \begingroup
  \begingroup
    \vglue\titlepagetopglue
    \vglue\titlepagetopglue
    \titlefonts \rm
    \titlefonts \rm
    \leftline{Part #1:@* #2}
    \leftline{Part #1:@* #2}
    \vskip4pt \hrule height 4pt width \hsize \vskip4pt
    \vskip4pt \hrule height 4pt width \hsize \vskip4pt
  \endgroup
  \endgroup
  \writetocentry{part}{#2}{#1}
  \writetocentry{part}{#2}{#1}
}
}
\gdef\blankpart{%
\gdef\blankpart{%
  \writetocentry{blankpart}{}{}
  \writetocentry{blankpart}{}{}
}
}
% Part TOC-entry definition for summary contents.
% Part TOC-entry definition for summary contents.
\gdef\dosmallpartentry#1#2#3#4{%
\gdef\dosmallpartentry#1#2#3#4{%
  \vskip .5\baselineskip plus.2\baselineskip
  \vskip .5\baselineskip plus.2\baselineskip
  \begingroup
  \begingroup
    \let\rm=\bf \rm
    \let\rm=\bf \rm
    \tocentry{Part #2: #1}{\doshortpageno\bgroup#4\egroup}
    \tocentry{Part #2: #1}{\doshortpageno\bgroup#4\egroup}
  \endgroup
  \endgroup
}
}
\gdef\dosmallblankpartentry#1#2#3#4{%
\gdef\dosmallblankpartentry#1#2#3#4{%
  \vskip .5\baselineskip plus.2\baselineskip
  \vskip .5\baselineskip plus.2\baselineskip
}
}
% Part TOC-entry definition for regular contents.  This has to be
% Part TOC-entry definition for regular contents.  This has to be
% equated to an existing entry to not cause problems when the PDF
% equated to an existing entry to not cause problems when the PDF
% outline is created.
% outline is created.
\gdef\dopartentry#1#2#3#4{%
\gdef\dopartentry#1#2#3#4{%
  \unnchapentry{Part #2: #1}{}{#3}{#4}
  \unnchapentry{Part #2: #1}{}{#3}{#4}
}
}
\gdef\doblankpartentry#1#2#3#4{}
\gdef\doblankpartentry#1#2#3#4{}
@end tex
@end tex
 
 
@c %**end of header
@c %**end of header
 
 
@c Use with @@smallbook.
@c Use with @@smallbook.
 
 
@c %** start of document
@c %** start of document
 
 
@c Cause even numbered pages to be printed on the left hand side of
@c Cause even numbered pages to be printed on the left hand side of
@c the page and odd numbered pages to be printed on the right hand
@c the page and odd numbered pages to be printed on the right hand
@c side of the page.  Using this, you can print on both sides of a
@c side of the page.  Using this, you can print on both sides of a
@c sheet of paper and have the text on the same part of the sheet.
@c sheet of paper and have the text on the same part of the sheet.
 
 
@c The text on right hand pages is pushed towards the right hand
@c The text on right hand pages is pushed towards the right hand
@c margin and the text on left hand pages is pushed toward the left
@c margin and the text on left hand pages is pushed toward the left
@c hand margin.
@c hand margin.
@c (To provide the reverse effect, set bindingoffset to -0.75in.)
@c (To provide the reverse effect, set bindingoffset to -0.75in.)
 
 
@c @tex
@c @tex
@c \global\bindingoffset=0.75in
@c \global\bindingoffset=0.75in
@c \global\normaloffset =0.75in
@c \global\normaloffset =0.75in
@c @end tex
@c @end tex
 
 
@copying
@copying
Copyright @copyright{} @value{copyrights-gfortran} Free Software Foundation, Inc.
Copyright @copyright{} @value{copyrights-gfortran} Free Software Foundation, Inc.
 
 
Permission is granted to copy, distribute and/or modify this document
Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.2 or
under the terms of the GNU Free Documentation License, Version 1.2 or
any later version published by the Free Software Foundation; with the
any later version published by the Free Software Foundation; with the
Invariant Sections being ``Funding Free Software'', the Front-Cover
Invariant Sections being ``Funding Free Software'', the Front-Cover
Texts being (a) (see below), and with the Back-Cover Texts being (b)
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
(see below).  A copy of the license is included in the section entitled
``GNU Free Documentation License''.
``GNU Free Documentation License''.
 
 
(a) The FSF's Front-Cover Text is:
(a) The FSF's Front-Cover Text is:
 
 
     A GNU Manual
     A GNU Manual
 
 
(b) The FSF's Back-Cover Text is:
(b) The FSF's Back-Cover Text is:
 
 
     You have freedom to copy and modify this GNU Manual, like GNU
     You have freedom to copy and modify this GNU Manual, like GNU
     software.  Copies published by the Free Software Foundation raise
     software.  Copies published by the Free Software Foundation raise
     funds for GNU development.
     funds for GNU development.
@end copying
@end copying
 
 
@ifinfo
@ifinfo
@dircategory Software development
@dircategory Software development
@direntry
@direntry
* gfortran: (gfortran).                  The GNU Fortran Compiler.
* gfortran: (gfortran).                  The GNU Fortran Compiler.
@end direntry
@end direntry
This file documents the use and the internals of
This file documents the use and the internals of
the GNU Fortran compiler, (@command{gfortran}).
the GNU Fortran compiler, (@command{gfortran}).
 
 
Published by the Free Software Foundation
Published by the Free Software Foundation
51 Franklin Street, Fifth Floor
51 Franklin Street, Fifth Floor
Boston, MA 02110-1301 USA
Boston, MA 02110-1301 USA
 
 
@insertcopying
@insertcopying
@end ifinfo
@end ifinfo
 
 
 
 
@setchapternewpage odd
@setchapternewpage odd
@titlepage
@titlepage
@title Using GNU Fortran
@title Using GNU Fortran
@versionsubtitle
@versionsubtitle
@author The @t{gfortran} team
@author The @t{gfortran} team
@page
@page
@vskip 0pt plus 1filll
@vskip 0pt plus 1filll
Published by the Free Software Foundation@*
Published by the Free Software Foundation@*
51 Franklin Street, Fifth Floor@*
51 Franklin Street, Fifth Floor@*
Boston, MA 02110-1301, USA@*
Boston, MA 02110-1301, USA@*
@c Last printed ??ber, 19??.@*
@c Last printed ??ber, 19??.@*
@c Printed copies are available for $? each.@*
@c Printed copies are available for $? each.@*
@c ISBN ???
@c ISBN ???
@sp 1
@sp 1
@insertcopying
@insertcopying
@end titlepage
@end titlepage
 
 
@c TODO: The following "Part" definitions are included here temporarily
@c TODO: The following "Part" definitions are included here temporarily
@c until they are incorporated into the official Texinfo distribution.
@c until they are incorporated into the official Texinfo distribution.
 
 
@tex
@tex
\global\let\partentry=\dosmallpartentry
\global\let\partentry=\dosmallpartentry
\global\let\blankpartentry=\dosmallblankpartentry
\global\let\blankpartentry=\dosmallblankpartentry
@end tex
@end tex
@summarycontents
@summarycontents
 
 
@tex
@tex
\global\let\partentry=\dopartentry
\global\let\partentry=\dopartentry
\global\let\blankpartentry=\doblankpartentry
\global\let\blankpartentry=\doblankpartentry
@end tex
@end tex
@contents
@contents
 
 
@page
@page
 
 
@c ---------------------------------------------------------------------
@c ---------------------------------------------------------------------
@c TexInfo table of contents.
@c TexInfo table of contents.
@c ---------------------------------------------------------------------
@c ---------------------------------------------------------------------
 
 
@ifnottex
@ifnottex
@node Top
@node Top
@top Introduction
@top Introduction
@cindex Introduction
@cindex Introduction
 
 
This manual documents the use of @command{gfortran},
This manual documents the use of @command{gfortran},
the GNU Fortran compiler. You can find in this manual how to invoke
the GNU Fortran compiler. You can find in this manual how to invoke
@command{gfortran}, as well as its features and incompatibilities.
@command{gfortran}, as well as its features and incompatibilities.
 
 
@ifset DEVELOPMENT
@ifset DEVELOPMENT
@emph{Warning:} This document, and the compiler it describes, are still
@emph{Warning:} This document, and the compiler it describes, are still
under development.  While efforts are made to keep it up-to-date, it might
under development.  While efforts are made to keep it up-to-date, it might
not accurately reflect the status of the most recent GNU Fortran compiler.
not accurately reflect the status of the most recent GNU Fortran compiler.
@end ifset
@end ifset
 
 
@comment
@comment
@comment  When you add a new menu item, please keep the right hand
@comment  When you add a new menu item, please keep the right hand
@comment  aligned to the same column.  Do not use tabs.  This provides
@comment  aligned to the same column.  Do not use tabs.  This provides
@comment  better formatting.
@comment  better formatting.
@comment
@comment
@menu
@menu
* Introduction::
* Introduction::
 
 
Part I: Invoking GNU Fortran
Part I: Invoking GNU Fortran
* Invoking GNU Fortran:: Command options supported by @command{gfortran}.
* Invoking GNU Fortran:: Command options supported by @command{gfortran}.
* Runtime::              Influencing runtime behavior with environment variables.
* Runtime::              Influencing runtime behavior with environment variables.
 
 
Part II: Language Reference
Part II: Language Reference
* Fortran 2003 and 2008 status::  Fortran 2003 and 2008 features supported by GNU Fortran.
* Fortran 2003 and 2008 status::  Fortran 2003 and 2008 features supported by GNU Fortran.
* Compiler Characteristics::      User-visible implementation details.
* Compiler Characteristics::      User-visible implementation details.
* Mixed-Language Programming::    Interoperability with C
* Mixed-Language Programming::    Interoperability with C
* Extensions::           Language extensions implemented by GNU Fortran.
* Extensions::           Language extensions implemented by GNU Fortran.
* Intrinsic Procedures:: Intrinsic procedures supported by GNU Fortran.
* Intrinsic Procedures:: Intrinsic procedures supported by GNU Fortran.
* Intrinsic Modules::    Intrinsic modules supported by GNU Fortran.
* Intrinsic Modules::    Intrinsic modules supported by GNU Fortran.
 
 
* Contributing::         How you can help.
* Contributing::         How you can help.
* Copying::              GNU General Public License says
* Copying::              GNU General Public License says
                         how you can copy and share GNU Fortran.
                         how you can copy and share GNU Fortran.
* GNU Free Documentation License::
* GNU Free Documentation License::
                         How you can copy and share this manual.
                         How you can copy and share this manual.
* Funding::              How to help assure continued work for free software.
* Funding::              How to help assure continued work for free software.
* Option Index::         Index of command line options
* Option Index::         Index of command line options
* Keyword Index::        Index of concepts
* Keyword Index::        Index of concepts
@end menu
@end menu
@end ifnottex
@end ifnottex
 
 
@c ---------------------------------------------------------------------
@c ---------------------------------------------------------------------
@c Introduction
@c Introduction
@c ---------------------------------------------------------------------
@c ---------------------------------------------------------------------
 
 
@node Introduction
@node Introduction
@chapter Introduction
@chapter Introduction
 
 
@c The following duplicates the text on the TexInfo table of contents.
@c The following duplicates the text on the TexInfo table of contents.
@iftex
@iftex
This manual documents the use of @command{gfortran}, the GNU Fortran
This manual documents the use of @command{gfortran}, the GNU Fortran
compiler. You can find in this manual how to invoke @command{gfortran},
compiler. You can find in this manual how to invoke @command{gfortran},
as well as its features and incompatibilities.
as well as its features and incompatibilities.
 
 
@ifset DEVELOPMENT
@ifset DEVELOPMENT
@emph{Warning:} This document, and the compiler it describes, are still
@emph{Warning:} This document, and the compiler it describes, are still
under development.  While efforts are made to keep it up-to-date, it
under development.  While efforts are made to keep it up-to-date, it
might not accurately reflect the status of the most recent GNU Fortran
might not accurately reflect the status of the most recent GNU Fortran
compiler.
compiler.
@end ifset
@end ifset
@end iftex
@end iftex
 
 
The GNU Fortran compiler front end was
The GNU Fortran compiler front end was
designed initially as a free replacement for,
designed initially as a free replacement for,
or alternative to, the unix @command{f95} command;
or alternative to, the unix @command{f95} command;
@command{gfortran} is the command you'll use to invoke the compiler.
@command{gfortran} is the command you'll use to invoke the compiler.
 
 
@menu
@menu
* About GNU Fortran::    What you should know about the GNU Fortran compiler.
* About GNU Fortran::    What you should know about the GNU Fortran compiler.
* GNU Fortran and GCC::  You can compile Fortran, C, or other programs.
* GNU Fortran and GCC::  You can compile Fortran, C, or other programs.
* Preprocessing and conditional compilation:: The Fortran preprocessor
* Preprocessing and conditional compilation:: The Fortran preprocessor
* GNU Fortran and G77::  Why we chose to start from scratch.
* GNU Fortran and G77::  Why we chose to start from scratch.
* Project Status::       Status of GNU Fortran, roadmap, proposed extensions.
* Project Status::       Status of GNU Fortran, roadmap, proposed extensions.
* Standards::            Standards supported by GNU Fortran.
* Standards::            Standards supported by GNU Fortran.
@end menu
@end menu
 
 
 
 
@c ---------------------------------------------------------------------
@c ---------------------------------------------------------------------
@c About GNU Fortran
@c About GNU Fortran
@c ---------------------------------------------------------------------
@c ---------------------------------------------------------------------
 
 
@node About GNU Fortran
@node About GNU Fortran
@section About GNU Fortran
@section About GNU Fortran
 
 
The GNU Fortran compiler supports the Fortran 77, 90 and 95 standards
The GNU Fortran compiler supports the Fortran 77, 90 and 95 standards
completely, parts of the Fortran 2003 and Fortran 2008 standards, and
completely, parts of the Fortran 2003 and Fortran 2008 standards, and
several vendor extensions. The development goal is to provide the
several vendor extensions. The development goal is to provide the
following features:
following features:
 
 
@itemize @bullet
@itemize @bullet
@item
@item
Read a user's program,
Read a user's program,
stored in a file and containing instructions written
stored in a file and containing instructions written
in Fortran 77, Fortran 90, Fortran 95, Fortran 2003 or Fortran 2008.
in Fortran 77, Fortran 90, Fortran 95, Fortran 2003 or Fortran 2008.
This file contains @dfn{source code}.
This file contains @dfn{source code}.
 
 
@item
@item
Translate the user's program into instructions a computer
Translate the user's program into instructions a computer
can carry out more quickly than it takes to translate the
can carry out more quickly than it takes to translate the
instructions in the first
instructions in the first
place.  The result after compilation of a program is
place.  The result after compilation of a program is
@dfn{machine code},
@dfn{machine code},
code designed to be efficiently translated and processed
code designed to be efficiently translated and processed
by a machine such as your computer.
by a machine such as your computer.
Humans usually aren't as good writing machine code
Humans usually aren't as good writing machine code
as they are at writing Fortran (or C++, Ada, or Java),
as they are at writing Fortran (or C++, Ada, or Java),
because it is easy to make tiny mistakes writing machine code.
because it is easy to make tiny mistakes writing machine code.
 
 
@item
@item
Provide the user with information about the reasons why
Provide the user with information about the reasons why
the compiler is unable to create a binary from the source code.
the compiler is unable to create a binary from the source code.
Usually this will be the case if the source code is flawed.
Usually this will be the case if the source code is flawed.
The Fortran 90 standard requires that the compiler can point out
The Fortran 90 standard requires that the compiler can point out
mistakes to the user.
mistakes to the user.
An incorrect usage of the language causes an @dfn{error message}.
An incorrect usage of the language causes an @dfn{error message}.
 
 
The compiler will also attempt to diagnose cases where the
The compiler will also attempt to diagnose cases where the
user's program contains a correct usage of the language,
user's program contains a correct usage of the language,
but instructs the computer to do something questionable.
but instructs the computer to do something questionable.
This kind of diagnostics message is called a @dfn{warning message}.
This kind of diagnostics message is called a @dfn{warning message}.
 
 
@item
@item
Provide optional information about the translation passes
Provide optional information about the translation passes
from the source code to machine code.
from the source code to machine code.
This can help a user of the compiler to find the cause of
This can help a user of the compiler to find the cause of
certain bugs which may not be obvious in the source code,
certain bugs which may not be obvious in the source code,
but may be more easily found at a lower level compiler output.
but may be more easily found at a lower level compiler output.
It also helps developers to find bugs in the compiler itself.
It also helps developers to find bugs in the compiler itself.
 
 
@item
@item
Provide information in the generated machine code that can
Provide information in the generated machine code that can
make it easier to find bugs in the program (using a debugging tool,
make it easier to find bugs in the program (using a debugging tool,
called a @dfn{debugger}, such as the GNU Debugger @command{gdb}).
called a @dfn{debugger}, such as the GNU Debugger @command{gdb}).
 
 
@item
@item
Locate and gather machine code already generated to
Locate and gather machine code already generated to
perform actions requested by statements in the user's program.
perform actions requested by statements in the user's program.
This machine code is organized into @dfn{modules} and is located
This machine code is organized into @dfn{modules} and is located
and @dfn{linked} to the user program.
and @dfn{linked} to the user program.
@end itemize
@end itemize
 
 
The GNU Fortran compiler consists of several components:
The GNU Fortran compiler consists of several components:
 
 
@itemize @bullet
@itemize @bullet
@item
@item
A version of the @command{gcc} command
A version of the @command{gcc} command
(which also might be installed as the system's @command{cc} command)
(which also might be installed as the system's @command{cc} command)
that also understands and accepts Fortran source code.
that also understands and accepts Fortran source code.
The @command{gcc} command is the @dfn{driver} program for
The @command{gcc} command is the @dfn{driver} program for
all the languages in the GNU Compiler Collection (GCC);
all the languages in the GNU Compiler Collection (GCC);
With @command{gcc},
With @command{gcc},
you can compile the source code of any language for
you can compile the source code of any language for
which a front end is available in GCC.
which a front end is available in GCC.
 
 
@item
@item
The @command{gfortran} command itself,
The @command{gfortran} command itself,
which also might be installed as the
which also might be installed as the
system's @command{f95} command.
system's @command{f95} command.
@command{gfortran} is just another driver program,
@command{gfortran} is just another driver program,
but specifically for the Fortran compiler only.
but specifically for the Fortran compiler only.
The difference with @command{gcc} is that @command{gfortran}
The difference with @command{gcc} is that @command{gfortran}
will automatically link the correct libraries to your program.
will automatically link the correct libraries to your program.
 
 
@item
@item
A collection of run-time libraries.
A collection of run-time libraries.
These libraries contain the machine code needed to support
These libraries contain the machine code needed to support
capabilities of the Fortran language that are not directly
capabilities of the Fortran language that are not directly
provided by the machine code generated by the
provided by the machine code generated by the
@command{gfortran} compilation phase,
@command{gfortran} compilation phase,
such as intrinsic functions and subroutines,
such as intrinsic functions and subroutines,
and routines for interaction with files and the operating system.
and routines for interaction with files and the operating system.
@c and mechanisms to spawn,
@c and mechanisms to spawn,
@c unleash and pause threads in parallelized code.
@c unleash and pause threads in parallelized code.
 
 
@item
@item
The Fortran compiler itself, (@command{f951}).
The Fortran compiler itself, (@command{f951}).
This is the GNU Fortran parser and code generator,
This is the GNU Fortran parser and code generator,
linked to and interfaced with the GCC backend library.
linked to and interfaced with the GCC backend library.
@command{f951} ``translates'' the source code to
@command{f951} ``translates'' the source code to
assembler code.  You would typically not use this
assembler code.  You would typically not use this
program directly;
program directly;
instead, the @command{gcc} or @command{gfortran} driver
instead, the @command{gcc} or @command{gfortran} driver
programs will call it for you.
programs will call it for you.
@end itemize
@end itemize
 
 
 
 
@c ---------------------------------------------------------------------
@c ---------------------------------------------------------------------
@c GNU Fortran and GCC
@c GNU Fortran and GCC
@c ---------------------------------------------------------------------
@c ---------------------------------------------------------------------
 
 
@node GNU Fortran and GCC
@node GNU Fortran and GCC
@section GNU Fortran and GCC
@section GNU Fortran and GCC
@cindex GNU Compiler Collection
@cindex GNU Compiler Collection
@cindex GCC
@cindex GCC
 
 
GNU Fortran is a part of GCC, the @dfn{GNU Compiler Collection}.  GCC
GNU Fortran is a part of GCC, the @dfn{GNU Compiler Collection}.  GCC
consists of a collection of front ends for various languages, which
consists of a collection of front ends for various languages, which
translate the source code into a language-independent form called
translate the source code into a language-independent form called
@dfn{GENERIC}.  This is then processed by a common middle end which
@dfn{GENERIC}.  This is then processed by a common middle end which
provides optimization, and then passed to one of a collection of back
provides optimization, and then passed to one of a collection of back
ends which generate code for different computer architectures and
ends which generate code for different computer architectures and
operating systems.
operating systems.
 
 
Functionally, this is implemented with a driver program (@command{gcc})
Functionally, this is implemented with a driver program (@command{gcc})
which provides the command-line interface for the compiler.  It calls
which provides the command-line interface for the compiler.  It calls
the relevant compiler front-end program (e.g., @command{f951} for
the relevant compiler front-end program (e.g., @command{f951} for
Fortran) for each file in the source code, and then calls the assembler
Fortran) for each file in the source code, and then calls the assembler
and linker as appropriate to produce the compiled output. In a copy of
and linker as appropriate to produce the compiled output. In a copy of
GCC which has been compiled with Fortran language support enabled,
GCC which has been compiled with Fortran language support enabled,
@command{gcc} will recognize files with @file{.f}, @file{.for}, @file{.ftn},
@command{gcc} will recognize files with @file{.f}, @file{.for}, @file{.ftn},
@file{.f90}, @file{.f95}, @file{.f03} and @file{.f08} extensions as
@file{.f90}, @file{.f95}, @file{.f03} and @file{.f08} extensions as
Fortran source code, and compile it accordingly. A @command{gfortran}
Fortran source code, and compile it accordingly. A @command{gfortran}
driver program is also provided, which is identical to @command{gcc}
driver program is also provided, which is identical to @command{gcc}
except that it automatically links the Fortran runtime libraries into the
except that it automatically links the Fortran runtime libraries into the
compiled program.
compiled program.
 
 
Source files with @file{.f}, @file{.for}, @file{.fpp}, @file{.ftn}, @file{.F},
Source files with @file{.f}, @file{.for}, @file{.fpp}, @file{.ftn}, @file{.F},
@file{.FOR}, @file{.FPP}, and @file{.FTN} extensions are treated as fixed form.
@file{.FOR}, @file{.FPP}, and @file{.FTN} extensions are treated as fixed form.
Source files with @file{.f90}, @file{.f95}, @file{.f03}, @file{.f08},
Source files with @file{.f90}, @file{.f95}, @file{.f03}, @file{.f08},
@file{.F90}, @file{.F95}, @file{.F03} and @file{.F08} extensions are
@file{.F90}, @file{.F95}, @file{.F03} and @file{.F08} extensions are
treated as free form.  The capitalized versions of either form are run
treated as free form.  The capitalized versions of either form are run
through preprocessing. Source files with the lower case @file{.fpp}
through preprocessing. Source files with the lower case @file{.fpp}
extension are also run through preprocessing.
extension are also run through preprocessing.
 
 
This manual specifically documents the Fortran front end, which handles
This manual specifically documents the Fortran front end, which handles
the programming language's syntax and semantics.  The aspects of GCC
the programming language's syntax and semantics.  The aspects of GCC
which relate to the optimization passes and the back-end code generation
which relate to the optimization passes and the back-end code generation
are documented in the GCC manual; see
are documented in the GCC manual; see
@ref{Top,,Introduction,gcc,Using the GNU Compiler Collection (GCC)}.
@ref{Top,,Introduction,gcc,Using the GNU Compiler Collection (GCC)}.
The two manuals together provide a complete reference for the GNU
The two manuals together provide a complete reference for the GNU
Fortran compiler.
Fortran compiler.
 
 
 
 
@c ---------------------------------------------------------------------
@c ---------------------------------------------------------------------
@c Preprocessing and conditional compilation
@c Preprocessing and conditional compilation
@c ---------------------------------------------------------------------
@c ---------------------------------------------------------------------
 
 
@node Preprocessing and conditional compilation
@node Preprocessing and conditional compilation
@section Preprocessing and conditional compilation
@section Preprocessing and conditional compilation
@cindex CPP
@cindex CPP
@cindex FPP
@cindex FPP
@cindex Conditional compilation
@cindex Conditional compilation
@cindex Preprocessing
@cindex Preprocessing
@cindex preprocessor, include file handling
@cindex preprocessor, include file handling
 
 
Many Fortran compilers including GNU Fortran allow passing the source code
Many Fortran compilers including GNU Fortran allow passing the source code
through a C preprocessor (CPP; sometimes also called the Fortran preprocessor,
through a C preprocessor (CPP; sometimes also called the Fortran preprocessor,
FPP) to allow for conditional compilation. In the case of GNU Fortran,
FPP) to allow for conditional compilation. In the case of GNU Fortran,
this is the GNU C Preprocessor in the traditional mode. On systems with
this is the GNU C Preprocessor in the traditional mode. On systems with
case-preserving file names, the preprocessor is automatically invoked if the
case-preserving file names, the preprocessor is automatically invoked if the
filename extension is @code{.F}, @code{.FOR}, @code{.FTN}, @code{.fpp},
filename extension is @code{.F}, @code{.FOR}, @code{.FTN}, @code{.fpp},
@code{.FPP}, @code{.F90}, @code{.F95}, @code{.F03} or @code{.F08}. To manually
@code{.FPP}, @code{.F90}, @code{.F95}, @code{.F03} or @code{.F08}. To manually
invoke the preprocessor on any file, use @option{-cpp}, to disable
invoke the preprocessor on any file, use @option{-cpp}, to disable
preprocessing on files where the preprocessor is run automatically, use
preprocessing on files where the preprocessor is run automatically, use
@option{-nocpp}.
@option{-nocpp}.
 
 
If a preprocessed file includes another file with the Fortran @code{INCLUDE}
If a preprocessed file includes another file with the Fortran @code{INCLUDE}
statement, the included file is not preprocessed. To preprocess included
statement, the included file is not preprocessed. To preprocess included
files, use the equivalent preprocessor statement @code{#include}.
files, use the equivalent preprocessor statement @code{#include}.
 
 
If GNU Fortran invokes the preprocessor, @code{__GFORTRAN__}
If GNU Fortran invokes the preprocessor, @code{__GFORTRAN__}
is defined and @code{__GNUC__}, @code{__GNUC_MINOR__} and
is defined and @code{__GNUC__}, @code{__GNUC_MINOR__} and
@code{__GNUC_PATCHLEVEL__} can be used to determine the version of the
@code{__GNUC_PATCHLEVEL__} can be used to determine the version of the
compiler. See @ref{Top,,Overview,cpp,The C Preprocessor} for details.
compiler. See @ref{Top,,Overview,cpp,The C Preprocessor} for details.
 
 
While CPP is the de-facto standard for preprocessing Fortran code,
While CPP is the de-facto standard for preprocessing Fortran code,
Part 3 of the Fortran 95 standard (ISO/IEC 1539-3:1998) defines
Part 3 of the Fortran 95 standard (ISO/IEC 1539-3:1998) defines
Conditional Compilation, which is not widely used and not directly
Conditional Compilation, which is not widely used and not directly
supported by the GNU Fortran compiler. You can use the program coco
supported by the GNU Fortran compiler. You can use the program coco
to preprocess such files (@uref{http://users.erols.com/dnagle/coco.html}).
to preprocess such files (@uref{http://users.erols.com/dnagle/coco.html}).
 
 
 
 
@c ---------------------------------------------------------------------
@c ---------------------------------------------------------------------
@c GNU Fortran and G77
@c GNU Fortran and G77
@c ---------------------------------------------------------------------
@c ---------------------------------------------------------------------
 
 
@node GNU Fortran and G77
@node GNU Fortran and G77
@section GNU Fortran and G77
@section GNU Fortran and G77
@cindex Fortran 77
@cindex Fortran 77
@cindex @command{g77}
@cindex @command{g77}
 
 
The GNU Fortran compiler is the successor to @command{g77}, the Fortran
The GNU Fortran compiler is the successor to @command{g77}, the Fortran
77 front end included in GCC prior to version 4.  It is an entirely new
77 front end included in GCC prior to version 4.  It is an entirely new
program that has been designed to provide Fortran 95 support and
program that has been designed to provide Fortran 95 support and
extensibility for future Fortran language standards, as well as providing
extensibility for future Fortran language standards, as well as providing
backwards compatibility for Fortran 77 and nearly all of the GNU language
backwards compatibility for Fortran 77 and nearly all of the GNU language
extensions supported by @command{g77}.
extensions supported by @command{g77}.
 
 
 
 
@c ---------------------------------------------------------------------
@c ---------------------------------------------------------------------
@c Project Status
@c Project Status
@c ---------------------------------------------------------------------
@c ---------------------------------------------------------------------
 
 
@node Project Status
@node Project Status
@section Project Status
@section Project Status
 
 
@quotation
@quotation
As soon as @command{gfortran} can parse all of the statements correctly,
As soon as @command{gfortran} can parse all of the statements correctly,
it will be in the ``larva'' state.
it will be in the ``larva'' state.
When we generate code, the ``puppa'' state.
When we generate code, the ``puppa'' state.
When @command{gfortran} is done,
When @command{gfortran} is done,
we'll see if it will be a beautiful butterfly,
we'll see if it will be a beautiful butterfly,
or just a big bug....
or just a big bug....
 
 
--Andy Vaught, April 2000
--Andy Vaught, April 2000
@end quotation
@end quotation
 
 
The start of the GNU Fortran 95 project was announced on
The start of the GNU Fortran 95 project was announced on
the GCC homepage in March 18, 2000
the GCC homepage in March 18, 2000
(even though Andy had already been working on it for a while,
(even though Andy had already been working on it for a while,
of course).
of course).
 
 
The GNU Fortran compiler is able to compile nearly all
The GNU Fortran compiler is able to compile nearly all
standard-compliant Fortran 95, Fortran 90, and Fortran 77 programs,
standard-compliant Fortran 95, Fortran 90, and Fortran 77 programs,
including a number of standard and non-standard extensions, and can be
including a number of standard and non-standard extensions, and can be
used on real-world programs.  In particular, the supported extensions
used on real-world programs.  In particular, the supported extensions
include OpenMP, Cray-style pointers, and several Fortran 2003 and Fortran
include OpenMP, Cray-style pointers, and several Fortran 2003 and Fortran
2008 features such as enumeration, stream I/O, and some of the
2008 features such as enumeration, stream I/O, and some of the
enhancements to allocatable array support from TR 15581.  However, it is
enhancements to allocatable array support from TR 15581.  However, it is
still under development and has a few remaining rough edges.
still under development and has a few remaining rough edges.
 
 
At present, the GNU Fortran compiler passes the
At present, the GNU Fortran compiler passes the
@uref{http://www.fortran-2000.com/ArnaudRecipes/fcvs21_f95.html,
@uref{http://www.fortran-2000.com/ArnaudRecipes/fcvs21_f95.html,
NIST Fortran 77 Test Suite}, and produces acceptable results on the
NIST Fortran 77 Test Suite}, and produces acceptable results on the
@uref{http://www.netlib.org/lapack/faq.html#1.21, LAPACK Test Suite}.
@uref{http://www.netlib.org/lapack/faq.html#1.21, LAPACK Test Suite}.
It also provides respectable performance on
It also provides respectable performance on
the @uref{http://www.polyhedron.com/pb05.html, Polyhedron Fortran
the @uref{http://www.polyhedron.com/pb05.html, Polyhedron Fortran
compiler benchmarks} and the
compiler benchmarks} and the
@uref{http://www.llnl.gov/asci_benchmarks/asci/limited/lfk/README.html,
@uref{http://www.llnl.gov/asci_benchmarks/asci/limited/lfk/README.html,
Livermore Fortran Kernels test}.  It has been used to compile a number of
Livermore Fortran Kernels test}.  It has been used to compile a number of
large real-world programs, including
large real-world programs, including
@uref{http://mysite.verizon.net/serveall/moene.pdf, the HIRLAM
@uref{http://mysite.verizon.net/serveall/moene.pdf, the HIRLAM
weather-forecasting code} and
weather-forecasting code} and
@uref{http://www.theochem.uwa.edu.au/tonto/, the Tonto quantum
@uref{http://www.theochem.uwa.edu.au/tonto/, the Tonto quantum
chemistry package}; see @url{http://gcc.gnu.org/wiki/GfortranApps} for an
chemistry package}; see @url{http://gcc.gnu.org/wiki/GfortranApps} for an
extended list.
extended list.
 
 
Among other things, the GNU Fortran compiler is intended as a replacement
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
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
G77 can be compiled with GNU Fortran, although there are a few minor known
regressions.
regressions.
 
 
The primary work remaining to be done on GNU Fortran falls into three
The primary work remaining to be done on GNU Fortran falls into three
categories: bug fixing (primarily regarding the treatment of invalid code
categories: bug fixing (primarily regarding the treatment of invalid code
and providing useful error messages), improving the compiler optimizations
and providing useful error messages), improving the compiler optimizations
and the performance of compiled code, and extending the compiler to support
and the performance of compiled code, and extending the compiler to support
future standards---in particular, Fortran 2003 and Fortran 2008.
future standards---in particular, Fortran 2003 and Fortran 2008.
 
 
 
 
@c ---------------------------------------------------------------------
@c ---------------------------------------------------------------------
@c Standards
@c Standards
@c ---------------------------------------------------------------------
@c ---------------------------------------------------------------------
 
 
@node Standards
@node Standards
@section Standards
@section Standards
@cindex Standards
@cindex Standards
 
 
@menu
@menu
* Varying Length Character Strings::
* Varying Length Character Strings::
@end menu
@end menu
 
 
The GNU Fortran compiler implements
The GNU Fortran compiler implements
ISO/IEC 1539:1997 (Fortran 95).  As such, it can also compile essentially all
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
standard-compliant Fortran 90 and Fortran 77 programs.   It also supports
the ISO/IEC TR-15581 enhancements to allocatable arrays, and
the ISO/IEC TR-15581 enhancements to allocatable arrays, and
the @uref{http://www.openmp.org/drupal/mp-documents/spec25.pdf,
the @uref{http://www.openmp.org/drupal/mp-documents/spec25.pdf,
OpenMP Application Program Interface v2.5} specification.
OpenMP Application Program Interface v2.5} specification.
 
 
In the future, the GNU Fortran compiler will also support ISO/IEC
In the future, the GNU Fortran compiler will also support ISO/IEC
1539-1:2004 (Fortran 2003) and future Fortran standards. Partial support
1539-1:2004 (Fortran 2003) and future Fortran standards. Partial support
of that standard is already provided; the current status of Fortran 2003
of that standard is already provided; the current status of Fortran 2003
support is reported in the @ref{Fortran 2003 status} section of the
support is reported in the @ref{Fortran 2003 status} section of the
documentation.
documentation.
 
 
The next version of the Fortran standard (Fortran 2008) is currently
The next version of the Fortran standard (Fortran 2008) is currently
being developed and the GNU Fortran compiler supports some of its new
being developed and the GNU Fortran compiler supports some of its new
features. This support is based on the latest draft of the standard
features. This support is based on the latest draft of the standard
(available from @url{http://www.nag.co.uk/sc22wg5/}) and no guarantee of
(available from @url{http://www.nag.co.uk/sc22wg5/}) and no guarantee of
future compatibility is made, as the final standard might differ from the
future compatibility is made, as the final standard might differ from the
draft. For more information, see the @ref{Fortran 2008 status} section.
draft. For more information, see the @ref{Fortran 2008 status} section.
 
 
Additionally, the GNU Fortran compilers supports the OpenMP specification
Additionally, the GNU Fortran compilers supports the OpenMP specification
(version 3.0, @url{http://openmp.org/wp/openmp-specifications/}).
(version 3.0, @url{http://openmp.org/wp/openmp-specifications/}).
 
 
@node Varying Length Character Strings
@node Varying Length Character Strings
@subsection Varying Length Character Strings
@subsection Varying Length Character Strings
@cindex Varying length character strings
@cindex Varying length character strings
@cindex Varying length strings
@cindex Varying length strings
@cindex strings, varying length
@cindex strings, varying length
 
 
The Fortran 95 standard specifies in Part 2 (ISO/IEC 1539-2:2000)
The Fortran 95 standard specifies in Part 2 (ISO/IEC 1539-2:2000)
varying length character strings. While GNU Fortran currently does not
varying length character strings. While GNU Fortran currently does not
support such strings directly, there exist two Fortran implementations
support such strings directly, there exist two Fortran implementations
for them, which work with GNU Fortran. They can be found at
for them, which work with GNU Fortran. They can be found at
@uref{http://www.fortran.com/@/iso_varying_string.f95} and at
@uref{http://www.fortran.com/@/iso_varying_string.f95} and at
@uref{ftp://ftp.nag.co.uk/@/sc22wg5/@/ISO_VARYING_STRING/}.
@uref{ftp://ftp.nag.co.uk/@/sc22wg5/@/ISO_VARYING_STRING/}.
 
 
 
 
 
 
@c =====================================================================
@c =====================================================================
@c PART I: INVOCATION REFERENCE
@c PART I: INVOCATION REFERENCE
@c =====================================================================
@c =====================================================================
 
 
@tex
@tex
\part{I}{Invoking GNU Fortran}
\part{I}{Invoking GNU Fortran}
@end tex
@end tex
 
 
@c ---------------------------------------------------------------------
@c ---------------------------------------------------------------------
@c Compiler Options
@c Compiler Options
@c ---------------------------------------------------------------------
@c ---------------------------------------------------------------------
 
 
@include invoke.texi
@include invoke.texi
 
 
 
 
@c ---------------------------------------------------------------------
@c ---------------------------------------------------------------------
@c Runtime
@c Runtime
@c ---------------------------------------------------------------------
@c ---------------------------------------------------------------------
 
 
@node Runtime
@node Runtime
@chapter Runtime:  Influencing runtime behavior with environment variables
@chapter Runtime:  Influencing runtime behavior with environment variables
@cindex environment variable
@cindex environment variable
 
 
The behavior of the @command{gfortran} can be influenced by
The behavior of the @command{gfortran} can be influenced by
environment variables.
environment variables.
 
 
Malformed environment variables are silently ignored.
Malformed environment variables are silently ignored.
 
 
@menu
@menu
* GFORTRAN_STDIN_UNIT:: Unit number for standard input
* GFORTRAN_STDIN_UNIT:: Unit number for standard input
* GFORTRAN_STDOUT_UNIT:: Unit number for standard output
* GFORTRAN_STDOUT_UNIT:: Unit number for standard output
* GFORTRAN_STDERR_UNIT:: Unit number for standard error
* GFORTRAN_STDERR_UNIT:: Unit number for standard error
* GFORTRAN_USE_STDERR:: Send library output to standard error
* GFORTRAN_USE_STDERR:: Send library output to standard error
* GFORTRAN_TMPDIR:: Directory for scratch files
* GFORTRAN_TMPDIR:: Directory for scratch files
* GFORTRAN_UNBUFFERED_ALL:: Don't buffer I/O for all units.
* GFORTRAN_UNBUFFERED_ALL:: Don't buffer I/O for all units.
* GFORTRAN_UNBUFFERED_PRECONNECTED:: Don't buffer I/O for preconnected units.
* GFORTRAN_UNBUFFERED_PRECONNECTED:: Don't buffer I/O for preconnected units.
* GFORTRAN_SHOW_LOCUS::  Show location for runtime errors
* GFORTRAN_SHOW_LOCUS::  Show location for runtime errors
* GFORTRAN_OPTIONAL_PLUS:: Print leading + where permitted
* GFORTRAN_OPTIONAL_PLUS:: Print leading + where permitted
* GFORTRAN_DEFAULT_RECL:: Default record length for new files
* GFORTRAN_DEFAULT_RECL:: Default record length for new files
* GFORTRAN_LIST_SEPARATOR::  Separator for list output
* GFORTRAN_LIST_SEPARATOR::  Separator for list output
* GFORTRAN_CONVERT_UNIT::  Set endianness for unformatted I/O
* GFORTRAN_CONVERT_UNIT::  Set endianness for unformatted I/O
* GFORTRAN_ERROR_DUMPCORE:: Dump core on run-time errors
* GFORTRAN_ERROR_DUMPCORE:: Dump core on run-time errors
* GFORTRAN_ERROR_BACKTRACE:: Show backtrace on run-time errors
* GFORTRAN_ERROR_BACKTRACE:: Show backtrace on run-time errors
@end menu
@end menu
 
 
@node GFORTRAN_STDIN_UNIT
@node GFORTRAN_STDIN_UNIT
@section @env{GFORTRAN_STDIN_UNIT}---Unit number for standard input
@section @env{GFORTRAN_STDIN_UNIT}---Unit number for standard input
 
 
This environment variable can be used to select the unit number
This environment variable can be used to select the unit number
preconnected to standard input.  This must be a positive integer.
preconnected to standard input.  This must be a positive integer.
The default value is 5.
The default value is 5.
 
 
@node GFORTRAN_STDOUT_UNIT
@node GFORTRAN_STDOUT_UNIT
@section @env{GFORTRAN_STDOUT_UNIT}---Unit number for standard output
@section @env{GFORTRAN_STDOUT_UNIT}---Unit number for standard output
 
 
This environment variable can be used to select the unit number
This environment variable can be used to select the unit number
preconnected to standard output.  This must be a positive integer.
preconnected to standard output.  This must be a positive integer.
The default value is 6.
The default value is 6.
 
 
@node GFORTRAN_STDERR_UNIT
@node GFORTRAN_STDERR_UNIT
@section @env{GFORTRAN_STDERR_UNIT}---Unit number for standard error
@section @env{GFORTRAN_STDERR_UNIT}---Unit number for standard error
 
 
This environment variable can be used to select the unit number
This environment variable can be used to select the unit number
preconnected to standard error.  This must be a positive integer.
preconnected to standard error.  This must be a positive integer.
The default value is 0.
The default value is 0.
 
 
@node GFORTRAN_USE_STDERR
@node GFORTRAN_USE_STDERR
@section @env{GFORTRAN_USE_STDERR}---Send library output to standard error
@section @env{GFORTRAN_USE_STDERR}---Send library output to standard error
 
 
This environment variable controls where library output is sent.
This environment variable controls where library output is sent.
If the first letter is @samp{y}, @samp{Y} or @samp{1}, standard
If the first letter is @samp{y}, @samp{Y} or @samp{1}, standard
error is used. If the first letter is @samp{n}, @samp{N} or
error is used. If the first letter is @samp{n}, @samp{N} or
@samp{0}, standard output is used.
@samp{0}, standard output is used.
 
 
@node GFORTRAN_TMPDIR
@node GFORTRAN_TMPDIR
@section @env{GFORTRAN_TMPDIR}---Directory for scratch files
@section @env{GFORTRAN_TMPDIR}---Directory for scratch files
 
 
This environment variable controls where scratch files are
This environment variable controls where scratch files are
created.  If this environment variable is missing,
created.  If this environment variable is missing,
GNU Fortran searches for the environment variable @env{TMP}.  If
GNU Fortran searches for the environment variable @env{TMP}.  If
this is also missing, the default is @file{/tmp}.
this is also missing, the default is @file{/tmp}.
 
 
@node GFORTRAN_UNBUFFERED_ALL
@node GFORTRAN_UNBUFFERED_ALL
@section @env{GFORTRAN_UNBUFFERED_ALL}---Don't buffer I/O on all units
@section @env{GFORTRAN_UNBUFFERED_ALL}---Don't buffer I/O on all units
 
 
This environment variable controls whether all I/O is unbuffered.  If
This environment variable controls whether all I/O is unbuffered.  If
the first letter is @samp{y}, @samp{Y} or @samp{1}, all I/O is
the first letter is @samp{y}, @samp{Y} or @samp{1}, all I/O is
unbuffered. This will slow down small sequential reads and writes.  If
unbuffered. This will slow down small sequential reads and writes.  If
the first letter is @samp{n}, @samp{N} or @samp{0}, I/O is buffered.
the first letter is @samp{n}, @samp{N} or @samp{0}, I/O is buffered.
This is the default.
This is the default.
 
 
@node GFORTRAN_UNBUFFERED_PRECONNECTED
@node GFORTRAN_UNBUFFERED_PRECONNECTED
@section @env{GFORTRAN_UNBUFFERED_PRECONNECTED}---Don't buffer I/O on preconnected units
@section @env{GFORTRAN_UNBUFFERED_PRECONNECTED}---Don't buffer I/O on preconnected units
 
 
The environment variable named @env{GFORTRAN_UNBUFFERED_PRECONNECTED} controls
The environment variable named @env{GFORTRAN_UNBUFFERED_PRECONNECTED} controls
whether I/O on a preconnected unit (i.e.@: STDOUT or STDERR) is unbuffered.  If
whether I/O on a preconnected unit (i.e.@: STDOUT or STDERR) is unbuffered.  If
the first letter is @samp{y}, @samp{Y} or @samp{1}, I/O is unbuffered. This
the first letter is @samp{y}, @samp{Y} or @samp{1}, I/O is unbuffered. This
will slow down small sequential reads and writes.  If the first letter
will slow down small sequential reads and writes.  If the first letter
is @samp{n}, @samp{N} or @samp{0}, I/O is buffered.  This is the default.
is @samp{n}, @samp{N} or @samp{0}, I/O is buffered.  This is the default.
 
 
@node GFORTRAN_SHOW_LOCUS
@node GFORTRAN_SHOW_LOCUS
@section @env{GFORTRAN_SHOW_LOCUS}---Show location for runtime errors
@section @env{GFORTRAN_SHOW_LOCUS}---Show location for runtime errors
 
 
If the first letter is @samp{y}, @samp{Y} or @samp{1}, filename and
If the first letter is @samp{y}, @samp{Y} or @samp{1}, filename and
line numbers for runtime errors are printed.  If the first letter is
line numbers for runtime errors are printed.  If the first letter is
@samp{n}, @samp{N} or @samp{0}, don't print filename and line numbers
@samp{n}, @samp{N} or @samp{0}, don't print filename and line numbers
for runtime errors. The default is to print the location.
for runtime errors. The default is to print the location.
 
 
@node GFORTRAN_OPTIONAL_PLUS
@node GFORTRAN_OPTIONAL_PLUS
@section @env{GFORTRAN_OPTIONAL_PLUS}---Print leading + where permitted
@section @env{GFORTRAN_OPTIONAL_PLUS}---Print leading + where permitted
 
 
If the first letter is @samp{y}, @samp{Y} or @samp{1},
If the first letter is @samp{y}, @samp{Y} or @samp{1},
a plus sign is printed
a plus sign is printed
where permitted by the Fortran standard.  If the first letter
where permitted by the Fortran standard.  If the first letter
is @samp{n}, @samp{N} or @samp{0}, a plus sign is not printed
is @samp{n}, @samp{N} or @samp{0}, a plus sign is not printed
in most cases. Default is not to print plus signs.
in most cases. Default is not to print plus signs.
 
 
@node GFORTRAN_DEFAULT_RECL
@node GFORTRAN_DEFAULT_RECL
@section @env{GFORTRAN_DEFAULT_RECL}---Default record length for new files
@section @env{GFORTRAN_DEFAULT_RECL}---Default record length for new files
 
 
This environment variable specifies the default record length, in
This environment variable specifies the default record length, in
bytes, for files which are opened without a @code{RECL} tag in the
bytes, for files which are opened without a @code{RECL} tag in the
@code{OPEN} statement.  This must be a positive integer.  The
@code{OPEN} statement.  This must be a positive integer.  The
default value is 1073741824 bytes (1 GB).
default value is 1073741824 bytes (1 GB).
 
 
@node GFORTRAN_LIST_SEPARATOR
@node GFORTRAN_LIST_SEPARATOR
@section @env{GFORTRAN_LIST_SEPARATOR}---Separator for list output
@section @env{GFORTRAN_LIST_SEPARATOR}---Separator for list output
 
 
This environment variable specifies the separator when writing
This environment variable specifies the separator when writing
list-directed output.  It may contain any number of spaces and
list-directed output.  It may contain any number of spaces and
at most one comma.  If you specify this on the command line,
at most one comma.  If you specify this on the command line,
be sure to quote spaces, as in
be sure to quote spaces, as in
@smallexample
@smallexample
$ GFORTRAN_LIST_SEPARATOR='  ,  ' ./a.out
$ GFORTRAN_LIST_SEPARATOR='  ,  ' ./a.out
@end smallexample
@end smallexample
when @command{a.out} is the compiled Fortran program that you want to run.
when @command{a.out} is the compiled Fortran program that you want to run.
Default is a single space.
Default is a single space.
 
 
@node GFORTRAN_CONVERT_UNIT
@node GFORTRAN_CONVERT_UNIT
@section @env{GFORTRAN_CONVERT_UNIT}---Set endianness for unformatted I/O
@section @env{GFORTRAN_CONVERT_UNIT}---Set endianness for unformatted I/O
 
 
By setting the @env{GFORTRAN_CONVERT_UNIT} variable, it is possible
By setting the @env{GFORTRAN_CONVERT_UNIT} variable, it is possible
to change the representation of data for unformatted files.
to change the representation of data for unformatted files.
The syntax for the @env{GFORTRAN_CONVERT_UNIT} variable is:
The syntax for the @env{GFORTRAN_CONVERT_UNIT} variable is:
@smallexample
@smallexample
GFORTRAN_CONVERT_UNIT: mode | mode ';' exception | exception ;
GFORTRAN_CONVERT_UNIT: mode | mode ';' exception | exception ;
mode: 'native' | 'swap' | 'big_endian' | 'little_endian' ;
mode: 'native' | 'swap' | 'big_endian' | 'little_endian' ;
exception: mode ':' unit_list | unit_list ;
exception: mode ':' unit_list | unit_list ;
unit_list: unit_spec | unit_list unit_spec ;
unit_list: unit_spec | unit_list unit_spec ;
unit_spec: INTEGER | INTEGER '-' INTEGER ;
unit_spec: INTEGER | INTEGER '-' INTEGER ;
@end smallexample
@end smallexample
The variable consists of an optional default mode, followed by
The variable consists of an optional default mode, followed by
a list of optional exceptions, which are separated by semicolons
a list of optional exceptions, which are separated by semicolons
from the preceding default and each other.  Each exception consists
from the preceding default and each other.  Each exception consists
of a format and a comma-separated list of units.  Valid values for
of a format and a comma-separated list of units.  Valid values for
the modes are the same as for the @code{CONVERT} specifier:
the modes are the same as for the @code{CONVERT} specifier:
 
 
@itemize @w{}
@itemize @w{}
@item @code{NATIVE} Use the native format.  This is the default.
@item @code{NATIVE} Use the native format.  This is the default.
@item @code{SWAP} Swap between little- and big-endian.
@item @code{SWAP} Swap between little- and big-endian.
@item @code{LITTLE_ENDIAN} Use the little-endian format
@item @code{LITTLE_ENDIAN} Use the little-endian format
for unformatted files.
for unformatted files.
@item @code{BIG_ENDIAN} Use the big-endian format for unformatted files.
@item @code{BIG_ENDIAN} Use the big-endian format for unformatted files.
@end itemize
@end itemize
A missing mode for an exception is taken to mean @code{BIG_ENDIAN}.
A missing mode for an exception is taken to mean @code{BIG_ENDIAN}.
Examples of values for @env{GFORTRAN_CONVERT_UNIT} are:
Examples of values for @env{GFORTRAN_CONVERT_UNIT} are:
@itemize @w{}
@itemize @w{}
@item @code{'big_endian'}  Do all unformatted I/O in big_endian mode.
@item @code{'big_endian'}  Do all unformatted I/O in big_endian mode.
@item @code{'little_endian;native:10-20,25'}  Do all unformatted I/O
@item @code{'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
in little_endian mode, except for units 10 to 20 and 25, which are in
native format.
native format.
@item @code{'10-20'}  Units 10 to 20 are big-endian, the rest is native.
@item @code{'10-20'}  Units 10 to 20 are big-endian, the rest is native.
@end itemize
@end itemize
 
 
Setting the environment variables should be done on the command
Setting the environment variables should be done on the command
line or via the @command{export}
line or via the @command{export}
command for @command{sh}-compatible shells and via @command{setenv}
command for @command{sh}-compatible shells and via @command{setenv}
for @command{csh}-compatible shells.
for @command{csh}-compatible shells.
 
 
Example for @command{sh}:
Example for @command{sh}:
@smallexample
@smallexample
$ gfortran foo.f90
$ gfortran foo.f90
$ GFORTRAN_CONVERT_UNIT='big_endian;native:10-20' ./a.out
$ GFORTRAN_CONVERT_UNIT='big_endian;native:10-20' ./a.out
@end smallexample
@end smallexample
 
 
Example code for @command{csh}:
Example code for @command{csh}:
@smallexample
@smallexample
% gfortran foo.f90
% gfortran foo.f90
% setenv GFORTRAN_CONVERT_UNIT 'big_endian;native:10-20'
% setenv GFORTRAN_CONVERT_UNIT 'big_endian;native:10-20'
% ./a.out
% ./a.out
@end smallexample
@end smallexample
 
 
Using anything but the native representation for unformatted data
Using anything but the native representation for unformatted data
carries a significant speed overhead.  If speed in this area matters
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
to you, it is best if you use this only for data that needs to be
portable.
portable.
 
 
@xref{CONVERT specifier}, for an alternative way to specify the
@xref{CONVERT specifier}, for an alternative way to specify the
data representation for unformatted files.  @xref{Runtime Options}, for
data representation for unformatted files.  @xref{Runtime Options}, for
setting a default data representation for the whole program.  The
setting a default data representation for the whole program.  The
@code{CONVERT} specifier overrides the @option{-fconvert} compile options.
@code{CONVERT} specifier overrides the @option{-fconvert} compile options.
 
 
@emph{Note that the values specified via the GFORTRAN_CONVERT_UNIT
@emph{Note that the values specified via the GFORTRAN_CONVERT_UNIT
environment variable will override the CONVERT specifier in the
environment variable will override the CONVERT specifier in the
open statement}.  This is to give control over data formats to
open statement}.  This is to give control over data formats to
users who do not have the source code of their program available.
users who do not have the source code of their program available.
 
 
@node GFORTRAN_ERROR_DUMPCORE
@node GFORTRAN_ERROR_DUMPCORE
@section @env{GFORTRAN_ERROR_DUMPCORE}---Dump core on run-time errors
@section @env{GFORTRAN_ERROR_DUMPCORE}---Dump core on run-time errors
 
 
If the @env{GFORTRAN_ERROR_DUMPCORE} variable is set to
If the @env{GFORTRAN_ERROR_DUMPCORE} variable is set to
@samp{y}, @samp{Y} or @samp{1} (only the first letter is relevant)
@samp{y}, @samp{Y} or @samp{1} (only the first letter is relevant)
then library run-time errors cause core dumps. To disable the core
then library run-time errors cause core dumps. To disable the core
dumps, set the variable to @samp{n}, @samp{N}, @samp{0}. Default
dumps, set the variable to @samp{n}, @samp{N}, @samp{0}. Default
is not to core dump unless the @option{-fdump-core} compile option
is not to core dump unless the @option{-fdump-core} compile option
was used.
was used.
 
 
@node GFORTRAN_ERROR_BACKTRACE
@node GFORTRAN_ERROR_BACKTRACE
@section @env{GFORTRAN_ERROR_BACKTRACE}---Show backtrace on run-time errors
@section @env{GFORTRAN_ERROR_BACKTRACE}---Show backtrace on run-time errors
 
 
If the @env{GFORTRAN_ERROR_BACKTRACE} variable is set to
If the @env{GFORTRAN_ERROR_BACKTRACE} variable is set to
@samp{y}, @samp{Y} or @samp{1} (only the first letter is relevant)
@samp{y}, @samp{Y} or @samp{1} (only the first letter is relevant)
then a backtrace is printed when a run-time error occurs.
then a backtrace is printed when a run-time error occurs.
To disable the backtracing, set the variable to
To disable the backtracing, set the variable to
@samp{n}, @samp{N}, @samp{0}. Default is not to print a backtrace
@samp{n}, @samp{N}, @samp{0}. Default is not to print a backtrace
unless the @option{-fbacktrace} compile option
unless the @option{-fbacktrace} compile option
was used.
was used.
 
 
@c =====================================================================
@c =====================================================================
@c PART II: LANGUAGE REFERENCE
@c PART II: LANGUAGE REFERENCE
@c =====================================================================
@c =====================================================================
 
 
@tex
@tex
\part{II}{Language Reference}
\part{II}{Language Reference}
@end tex
@end tex
 
 
@c ---------------------------------------------------------------------
@c ---------------------------------------------------------------------
@c Fortran 2003 and 2008 Status
@c Fortran 2003 and 2008 Status
@c ---------------------------------------------------------------------
@c ---------------------------------------------------------------------
 
 
@node Fortran 2003 and 2008 status
@node Fortran 2003 and 2008 status
@chapter Fortran 2003 and 2008 Status
@chapter Fortran 2003 and 2008 Status
 
 
@menu
@menu
* Fortran 2003 status::
* Fortran 2003 status::
* Fortran 2008 status::
* Fortran 2008 status::
@end menu
@end menu
 
 
@node Fortran 2003 status
@node Fortran 2003 status
@section Fortran 2003 status
@section Fortran 2003 status
 
 
GNU Fortran supports several Fortran 2003 features; an incomplete
GNU Fortran supports several Fortran 2003 features; an incomplete
list can be found below.  See also the
list can be found below.  See also the
@uref{http://gcc.gnu.org/wiki/Fortran2003, wiki page} about Fortran 2003.
@uref{http://gcc.gnu.org/wiki/Fortran2003, wiki page} about Fortran 2003.
 
 
@itemize
@itemize
@item
@item
Intrinsics @code{command_argument_count}, @code{get_command},
Intrinsics @code{command_argument_count}, @code{get_command},
@code{get_command_argument}, @code{get_environment_variable}, and
@code{get_command_argument}, @code{get_environment_variable}, and
@code{move_alloc}.
@code{move_alloc}.
 
 
@item
@item
@cindex array, constructors
@cindex array, constructors
@cindex @code{[...]}
@cindex @code{[...]}
Array constructors using square brackets. That is, @code{[...]} rather
Array constructors using square brackets. That is, @code{[...]} rather
than @code{(/.../)}.  Type-specification for array constructors like
than @code{(/.../)}.  Type-specification for array constructors like
@code{(/ some-type :: ... /)}.
@code{(/ some-type :: ... /)}.
 
 
@item
@item
@cindex @code{FLUSH} statement
@cindex @code{FLUSH} statement
@cindex statement, @code{FLUSH}
@cindex statement, @code{FLUSH}
@code{FLUSH} statement.
@code{FLUSH} statement.
 
 
@item
@item
@cindex @code{IOMSG=} specifier
@cindex @code{IOMSG=} specifier
@code{IOMSG=} specifier for I/O statements.
@code{IOMSG=} specifier for I/O statements.
 
 
@item
@item
@cindex @code{ENUM} statement
@cindex @code{ENUM} statement
@cindex @code{ENUMERATOR} statement
@cindex @code{ENUMERATOR} statement
@cindex statement, @code{ENUM}
@cindex statement, @code{ENUM}
@cindex statement, @code{ENUMERATOR}
@cindex statement, @code{ENUMERATOR}
@opindex @code{fshort-enums}
@opindex @code{fshort-enums}
Support for the declaration of enumeration constants via the
Support for the declaration of enumeration constants via the
@code{ENUM} and @code{ENUMERATOR} statements.  Interoperability with
@code{ENUM} and @code{ENUMERATOR} statements.  Interoperability with
@command{gcc} is guaranteed also for the case where the
@command{gcc} is guaranteed also for the case where the
@command{-fshort-enums} command line option is given.
@command{-fshort-enums} command line option is given.
 
 
@item
@item
@cindex TR 15581
@cindex TR 15581
TR 15581:
TR 15581:
@itemize
@itemize
@item
@item
@cindex @code{ALLOCATABLE} dummy arguments
@cindex @code{ALLOCATABLE} dummy arguments
@code{ALLOCATABLE} dummy arguments.
@code{ALLOCATABLE} dummy arguments.
@item
@item
@cindex @code{ALLOCATABLE} function results
@cindex @code{ALLOCATABLE} function results
@code{ALLOCATABLE} function results
@code{ALLOCATABLE} function results
@item
@item
@cindex @code{ALLOCATABLE} components of derived types
@cindex @code{ALLOCATABLE} components of derived types
@code{ALLOCATABLE} components of derived types
@code{ALLOCATABLE} components of derived types
@end itemize
@end itemize
 
 
@item
@item
@cindex @code{ALLOCATE}
@cindex @code{ALLOCATE}
The @code{ERRMSG=} tag is now supported in @code{ALLOCATE} and
The @code{ERRMSG=} tag is now supported in @code{ALLOCATE} and
@code{DEALLOCATE} statements.  The @code{SOURCE=} tag is supported
@code{DEALLOCATE} statements.  The @code{SOURCE=} tag is supported
in an @code{ALLOCATE} statement.  An @emph{intrinsic-type-spec}
in an @code{ALLOCATE} statement.  An @emph{intrinsic-type-spec}
can be used as the @emph{type-spec} in an @code{ALLOCATE} statement;
can be used as the @emph{type-spec} in an @code{ALLOCATE} statement;
while the use of a @emph{derived-type-name} is currently unsupported.
while the use of a @emph{derived-type-name} is currently unsupported.
 
 
@item
@item
@cindex @code{STREAM} I/O
@cindex @code{STREAM} I/O
@cindex @code{ACCESS='STREAM'} I/O
@cindex @code{ACCESS='STREAM'} I/O
The @code{OPEN} statement supports the @code{ACCESS='STREAM'} specifier,
The @code{OPEN} statement supports the @code{ACCESS='STREAM'} specifier,
allowing I/O without any record structure.
allowing I/O without any record structure.
 
 
@item
@item
Namelist input/output for internal files.
Namelist input/output for internal files.
 
 
@item
@item
@cindex @code{PROTECTED} statement
@cindex @code{PROTECTED} statement
@cindex statement, @code{PROTECTED}
@cindex statement, @code{PROTECTED}
The @code{PROTECTED} statement and attribute.
The @code{PROTECTED} statement and attribute.
 
 
@item
@item
@cindex @code{VALUE} statement
@cindex @code{VALUE} statement
@cindex statement, @code{VALUE}
@cindex statement, @code{VALUE}
The @code{VALUE} statement and attribute.
The @code{VALUE} statement and attribute.
 
 
@item
@item
@cindex @code{VOLATILE} statement
@cindex @code{VOLATILE} statement
@cindex statement, @code{VOLATILE}
@cindex statement, @code{VOLATILE}
The @code{VOLATILE} statement and attribute.
The @code{VOLATILE} statement and attribute.
 
 
@item
@item
@cindex @code{IMPORT} statement
@cindex @code{IMPORT} statement
@cindex statement, @code{IMPORT}
@cindex statement, @code{IMPORT}
The @code{IMPORT} statement, allowing to import
The @code{IMPORT} statement, allowing to import
host-associated derived types.
host-associated derived types.
 
 
@item
@item
@cindex @code{USE, INTRINSIC} statement
@cindex @code{USE, INTRINSIC} statement
@cindex statement, @code{USE, INTRINSIC}
@cindex statement, @code{USE, INTRINSIC}
@cindex @code{ISO_FORTRAN_ENV} statement
@cindex @code{ISO_FORTRAN_ENV} statement
@cindex statement, @code{ISO_FORTRAN_ENV}
@cindex statement, @code{ISO_FORTRAN_ENV}
@code{USE} statement with @code{INTRINSIC} and @code{NON_INTRINSIC}
@code{USE} statement with @code{INTRINSIC} and @code{NON_INTRINSIC}
attribute; supported intrinsic modules: @code{ISO_FORTRAN_ENV},
attribute; supported intrinsic modules: @code{ISO_FORTRAN_ENV},
@code{OMP_LIB} and @code{OMP_LIB_KINDS}.
@code{OMP_LIB} and @code{OMP_LIB_KINDS}.
 
 
@item
@item
Renaming of operators in the @code{USE} statement.
Renaming of operators in the @code{USE} statement.
 
 
@item
@item
@cindex ISO C Bindings
@cindex ISO C Bindings
Interoperability with C (ISO C Bindings)
Interoperability with C (ISO C Bindings)
 
 
@item
@item
BOZ as argument of @code{INT}, @code{REAL}, @code{DBLE} and @code{CMPLX}.
BOZ as argument of @code{INT}, @code{REAL}, @code{DBLE} and @code{CMPLX}.
 
 
@item
@item
@cindex type-bound procedure
@cindex type-bound procedure
@cindex type-bound operator
@cindex type-bound operator
Type-bound procedures with @code{PROCEDURE} or @code{GENERIC}, and operators
Type-bound procedures with @code{PROCEDURE} or @code{GENERIC}, and operators
bound to a derived-type.
bound to a derived-type.
 
 
@item
@item
@cindex @code{EXTENDS}
@cindex @code{EXTENDS}
@cindex derived-type extension
@cindex derived-type extension
Extension of derived-types (the @code{EXTENDS(...)} syntax).
Extension of derived-types (the @code{EXTENDS(...)} syntax).
 
 
@item
@item
@cindex @code{ABSTRACT} type
@cindex @code{ABSTRACT} type
@cindex @code{DEFERRED} procedure binding
@cindex @code{DEFERRED} procedure binding
@code{ABSTRACT} derived-types and declaring procedure bindings @code{DEFERRED}.
@code{ABSTRACT} derived-types and declaring procedure bindings @code{DEFERRED}.
 
 
@end itemize
@end itemize
 
 
 
 
@node Fortran 2008 status
@node Fortran 2008 status
@section Fortran 2008 status
@section Fortran 2008 status
 
 
The next version of the Fortran standard after Fortran 2003 is currently
The next version of the Fortran standard after Fortran 2003 is currently
being worked on by the Working Group 5 of Sub-Committee 22 of the Joint
being worked on by the Working Group 5 of Sub-Committee 22 of the Joint
Technical Committee 1 of the International Organization for
Technical Committee 1 of the International Organization for
Standardization (ISO) and the International Electrotechnical Commission
Standardization (ISO) and the International Electrotechnical Commission
(IEC). This group is known as @uref{http://www.nag.co.uk/sc22wg5/, WG5}.
(IEC). This group is known as @uref{http://www.nag.co.uk/sc22wg5/, WG5}.
The next revision of the Fortran standard is informally referred to as
The next revision of the Fortran standard is informally referred to as
Fortran 2008, reflecting its planned release year. The GNU Fortran
Fortran 2008, reflecting its planned release year. The GNU Fortran
compiler has support for some of the new features in Fortran 2008. This
compiler has support for some of the new features in Fortran 2008. This
support is based on the latest draft, available from
support is based on the latest draft, available from
@url{http://www.nag.co.uk/sc22wg5/}. However, as the final standard may
@url{http://www.nag.co.uk/sc22wg5/}. However, as the final standard may
differ from the drafts, no guarantee of backward compatibility can be
differ from the drafts, no guarantee of backward compatibility can be
made and you should only use it for experimental purposes.
made and you should only use it for experimental purposes.
 
 
The @uref{http://gcc.gnu.org/wiki/Fortran2008Status, wiki} has some information
The @uref{http://gcc.gnu.org/wiki/Fortran2008Status, wiki} has some information
about the current Fortran 2008 implementation status.
about the current Fortran 2008 implementation status.
 
 
 
 
@c ---------------------------------------------------------------------
@c ---------------------------------------------------------------------
@c Compiler Characteristics
@c Compiler Characteristics
@c ---------------------------------------------------------------------
@c ---------------------------------------------------------------------
 
 
@node Compiler Characteristics
@node Compiler Characteristics
@chapter Compiler Characteristics
@chapter Compiler Characteristics
 
 
This chapter describes certain characteristics of the GNU Fortran
This chapter describes certain characteristics of the GNU Fortran
compiler, that are not specified by the Fortran standard, but which
compiler, that are not specified by the Fortran standard, but which
might in some way or another become visible to the programmer.
might in some way or another become visible to the programmer.
 
 
@menu
@menu
* KIND Type Parameters::
* KIND Type Parameters::
* Internal representation of LOGICAL variables::
* Internal representation of LOGICAL variables::
@end menu
@end menu
 
 
 
 
@node KIND Type Parameters
@node KIND Type Parameters
@section KIND Type Parameters
@section KIND Type Parameters
@cindex kind
@cindex kind
 
 
The @code{KIND} type parameters supported by GNU Fortran for the primitive
The @code{KIND} type parameters supported by GNU Fortran for the primitive
data types are:
data types are:
 
 
@table @code
@table @code
 
 
@item INTEGER
@item INTEGER
1, 2, 4, 8*, 16*, default: 4 (1)
1, 2, 4, 8*, 16*, default: 4 (1)
 
 
@item LOGICAL
@item LOGICAL
1, 2, 4, 8*, 16*, default: 4 (1)
1, 2, 4, 8*, 16*, default: 4 (1)
 
 
@item REAL
@item REAL
4, 8, 10**, 16**, default: 4 (2)
4, 8, 10**, 16**, default: 4 (2)
 
 
@item COMPLEX
@item COMPLEX
4, 8, 10**, 16**, default: 4 (2)
4, 8, 10**, 16**, default: 4 (2)
 
 
@item CHARACTER
@item CHARACTER
1, 4, default: 1
1, 4, default: 1
 
 
@end table
@end table
 
 
@noindent
@noindent
* = not available on all systems @*
* = not available on all systems @*
** = not available on all systems; additionally 10 and 16 are never
** = not available on all systems; additionally 10 and 16 are never
available at the same time @*
available at the same time @*
(1) Unless -fdefault-integer-8 is used @*
(1) Unless -fdefault-integer-8 is used @*
(2) Unless -fdefault-real-8 is used
(2) Unless -fdefault-real-8 is used
 
 
@noindent
@noindent
The @code{KIND} value matches the storage size in bytes, except for
The @code{KIND} value matches the storage size in bytes, except for
@code{COMPLEX} where the storage size is twice as much (or both real and
@code{COMPLEX} where the storage size is twice as much (or both real and
imaginary part are a real value of the given size).  It is recommended to use
imaginary part are a real value of the given size).  It is recommended to use
the @code{SELECT_*_KIND} intrinsics instead of the concrete values.
the @code{SELECT_*_KIND} intrinsics instead of the concrete values.
 
 
 
 
@node Internal representation of LOGICAL variables
@node Internal representation of LOGICAL variables
@section Internal representation of LOGICAL variables
@section Internal representation of LOGICAL variables
@cindex logical, variable representation
@cindex logical, variable representation
 
 
The Fortran standard does not specify how variables of @code{LOGICAL}
The Fortran standard does not specify how variables of @code{LOGICAL}
type are represented, beyond requiring that @code{LOGICAL} variables
type are represented, beyond requiring that @code{LOGICAL} variables
of default kind have the same storage size as default @code{INTEGER}
of default kind have the same storage size as default @code{INTEGER}
and @code{REAL} variables.  The GNU Fortran internal representation is
and @code{REAL} variables.  The GNU Fortran internal representation is
as follows.
as follows.
 
 
A @code{LOGICAL(KIND=N)} variable is represented as an
A @code{LOGICAL(KIND=N)} variable is represented as an
@code{INTEGER(KIND=N)} variable, however, with only two permissible
@code{INTEGER(KIND=N)} variable, however, with only two permissible
values: @code{1} for @code{.TRUE.} and @code{0} for
values: @code{1} for @code{.TRUE.} and @code{0} for
@code{.FALSE.}. Any other integer value results in undefined behavior.
@code{.FALSE.}. Any other integer value results in undefined behavior.
 
 
Note that for mixed-language programming using the
Note that for mixed-language programming using the
@code{ISO_C_BINDING} feature, there is a @code{C_BOOL} kind that can
@code{ISO_C_BINDING} feature, there is a @code{C_BOOL} kind that can
be used to create @code{LOGICAL(KIND=C_BOOL)} variables which are
be used to create @code{LOGICAL(KIND=C_BOOL)} variables which are
interoperable with the C99 _Bool type.  The C99 _Bool type has an
interoperable with the C99 _Bool type.  The C99 _Bool type has an
internal representation described in the C99 standard, which is
internal representation described in the C99 standard, which is
identical to the above description, i.e. with 1 for true and 0 for
identical to the above description, i.e. with 1 for true and 0 for
false being the only permissible values.  Thus the internal
false being the only permissible values.  Thus the internal
representation of @code{LOGICAL} variables in GNU Fortran is identical
representation of @code{LOGICAL} variables in GNU Fortran is identical
to C99 _Bool, except for a possible difference in storage size
to C99 _Bool, except for a possible difference in storage size
depending on the kind.
depending on the kind.
 
 
@c ---------------------------------------------------------------------
@c ---------------------------------------------------------------------
@c Extensions
@c Extensions
@c ---------------------------------------------------------------------
@c ---------------------------------------------------------------------
 
 
@c Maybe this chapter should be merged with the 'Standards' section,
@c Maybe this chapter should be merged with the 'Standards' section,
@c whenever that is written :-)
@c whenever that is written :-)
 
 
@node Extensions
@node Extensions
@chapter Extensions
@chapter Extensions
@cindex extensions
@cindex extensions
 
 
The two sections below detail the extensions to standard Fortran that are
The two sections below detail the extensions to standard Fortran that are
implemented in GNU Fortran, as well as some of the popular or
implemented in GNU Fortran, as well as some of the popular or
historically important extensions that are not (or not yet) implemented.
historically important extensions that are not (or not yet) implemented.
For the latter case, we explain the alternatives available to GNU Fortran
For the latter case, we explain the alternatives available to GNU Fortran
users, including replacement by standard-conforming code or GNU
users, including replacement by standard-conforming code or GNU
extensions.
extensions.
 
 
@menu
@menu
* Extensions implemented in GNU Fortran::
* Extensions implemented in GNU Fortran::
* Extensions not implemented in GNU Fortran::
* Extensions not implemented in GNU Fortran::
@end menu
@end menu
 
 
 
 
@node Extensions implemented in GNU Fortran
@node Extensions implemented in GNU Fortran
@section Extensions implemented in GNU Fortran
@section Extensions implemented in GNU Fortran
@cindex extensions, implemented
@cindex extensions, implemented
 
 
GNU Fortran implements a number of extensions over standard
GNU Fortran implements a number of extensions over standard
Fortran. This chapter contains information on their syntax and
Fortran. This chapter contains information on their syntax and
meaning.  There are currently two categories of GNU Fortran
meaning.  There are currently two categories of GNU Fortran
extensions, those that provide functionality beyond that provided
extensions, those that provide functionality beyond that provided
by any standard, and those that are supported by GNU Fortran
by any standard, and those that are supported by GNU Fortran
purely for backward compatibility with legacy compilers.  By default,
purely for backward compatibility with legacy compilers.  By default,
@option{-std=gnu} allows the compiler to accept both types of
@option{-std=gnu} allows the compiler to accept both types of
extensions, but to warn about the use of the latter.  Specifying
extensions, but to warn about the use of the latter.  Specifying
either @option{-std=f95}, @option{-std=f2003} or @option{-std=f2008}
either @option{-std=f95}, @option{-std=f2003} or @option{-std=f2008}
disables both types of extensions, and @option{-std=legacy} allows both
disables both types of extensions, and @option{-std=legacy} allows both
without warning.
without warning.
 
 
@menu
@menu
* Old-style kind specifications::
* Old-style kind specifications::
* Old-style variable initialization::
* Old-style variable initialization::
* Extensions to namelist::
* Extensions to namelist::
* X format descriptor without count field::
* X format descriptor without count field::
* Commas in FORMAT specifications::
* Commas in FORMAT specifications::
* Missing period in FORMAT specifications::
* Missing period in FORMAT specifications::
* I/O item lists::
* I/O item lists::
* BOZ literal constants::
* BOZ literal constants::
* Real array indices::
* Real array indices::
* Unary operators::
* Unary operators::
* Implicitly convert LOGICAL and INTEGER values::
* Implicitly convert LOGICAL and INTEGER values::
* Hollerith constants support::
* Hollerith constants support::
* Cray pointers::
* Cray pointers::
* CONVERT specifier::
* CONVERT specifier::
* OpenMP::
* OpenMP::
* Argument list functions::
* Argument list functions::
@end menu
@end menu
 
 
@node Old-style kind specifications
@node Old-style kind specifications
@subsection Old-style kind specifications
@subsection Old-style kind specifications
@cindex kind, old-style
@cindex kind, old-style
 
 
GNU Fortran allows old-style kind specifications in declarations. These
GNU Fortran allows old-style kind specifications in declarations. These
look like:
look like:
@smallexample
@smallexample
      TYPESPEC*size x,y,z
      TYPESPEC*size x,y,z
@end smallexample
@end smallexample
@noindent
@noindent
where @code{TYPESPEC} is a basic type (@code{INTEGER}, @code{REAL},
where @code{TYPESPEC} is a basic type (@code{INTEGER}, @code{REAL},
etc.), and where @code{size} is a byte count corresponding to the
etc.), and where @code{size} is a byte count corresponding to the
storage size of a valid kind for that type.  (For @code{COMPLEX}
storage size of a valid kind for that type.  (For @code{COMPLEX}
variables, @code{size} is the total size of the real and imaginary
variables, @code{size} is the total size of the real and imaginary
parts.)  The statement then declares @code{x}, @code{y} and @code{z} to
parts.)  The statement then declares @code{x}, @code{y} and @code{z} to
be of type @code{TYPESPEC} with the appropriate kind.  This is
be of type @code{TYPESPEC} with the appropriate kind.  This is
equivalent to the standard-conforming declaration
equivalent to the standard-conforming declaration
@smallexample
@smallexample
      TYPESPEC(k) x,y,z
      TYPESPEC(k) x,y,z
@end smallexample
@end smallexample
@noindent
@noindent
where @code{k} is the kind parameter suitable for the intended precision.  As
where @code{k} is the kind parameter suitable for the intended precision.  As
kind parameters are implementation-dependent, use the @code{KIND},
kind parameters are implementation-dependent, use the @code{KIND},
@code{SELECTED_INT_KIND} and @code{SELECTED_REAL_KIND} intrinsics to retrieve
@code{SELECTED_INT_KIND} and @code{SELECTED_REAL_KIND} intrinsics to retrieve
the correct value, for instance @code{REAL*8 x} can be replaced by:
the correct value, for instance @code{REAL*8 x} can be replaced by:
@smallexample
@smallexample
INTEGER, PARAMETER :: dbl = KIND(1.0d0)
INTEGER, PARAMETER :: dbl = KIND(1.0d0)
REAL(KIND=dbl) :: x
REAL(KIND=dbl) :: x
@end smallexample
@end smallexample
 
 
@node Old-style variable initialization
@node Old-style variable initialization
@subsection Old-style variable initialization
@subsection Old-style variable initialization
 
 
GNU Fortran allows old-style initialization of variables of the
GNU Fortran allows old-style initialization of variables of the
form:
form:
@smallexample
@smallexample
      INTEGER i/1/,j/2/
      INTEGER i/1/,j/2/
      REAL x(2,2) /3*0.,1./
      REAL x(2,2) /3*0.,1./
@end smallexample
@end smallexample
The syntax for the initializers is as for the @code{DATA} statement, but
The syntax for the initializers is as for the @code{DATA} statement, but
unlike in a @code{DATA} statement, an initializer only applies to the
unlike in a @code{DATA} statement, an initializer only applies to the
variable immediately preceding the initialization.  In other words,
variable immediately preceding the initialization.  In other words,
something like @code{INTEGER I,J/2,3/} is not valid.  This style of
something like @code{INTEGER I,J/2,3/} is not valid.  This style of
initialization is only allowed in declarations without double colons
initialization is only allowed in declarations without double colons
(@code{::}); the double colons were introduced in Fortran 90, which also
(@code{::}); the double colons were introduced in Fortran 90, which also
introduced a standard syntax for initializing variables in type
introduced a standard syntax for initializing variables in type
declarations.
declarations.
 
 
Examples of standard-conforming code equivalent to the above example
Examples of standard-conforming code equivalent to the above example
are:
are:
@smallexample
@smallexample
! Fortran 90
! Fortran 90
      INTEGER :: i = 1, j = 2
      INTEGER :: i = 1, j = 2
      REAL :: x(2,2) = RESHAPE((/0.,0.,0.,1./),SHAPE(x))
      REAL :: x(2,2) = RESHAPE((/0.,0.,0.,1./),SHAPE(x))
! Fortran 77
! Fortran 77
      INTEGER i, j
      INTEGER i, j
      REAL x(2,2)
      REAL x(2,2)
      DATA i/1/, j/2/, x/3*0.,1./
      DATA i/1/, j/2/, x/3*0.,1./
@end smallexample
@end smallexample
 
 
Note that variables which are explicitly initialized in declarations
Note that variables which are explicitly initialized in declarations
or in @code{DATA} statements automatically acquire the @code{SAVE}
or in @code{DATA} statements automatically acquire the @code{SAVE}
attribute.
attribute.
 
 
@node Extensions to namelist
@node Extensions to namelist
@subsection Extensions to namelist
@subsection Extensions to namelist
@cindex Namelist
@cindex Namelist
 
 
GNU Fortran fully supports the Fortran 95 standard for namelist I/O
GNU Fortran fully supports the Fortran 95 standard for namelist I/O
including array qualifiers, substrings and fully qualified derived types.
including array qualifiers, substrings and fully qualified derived types.
The output from a namelist write is compatible with namelist read.  The
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
output has all names in upper case and indentation to column 1 after the
namelist name.  Two extensions are permitted:
namelist name.  Two extensions are permitted:
 
 
Old-style use of @samp{$} instead of @samp{&}
Old-style use of @samp{$} instead of @samp{&}
@smallexample
@smallexample
$MYNML
$MYNML
 X(:)%Y(2) = 1.0 2.0 3.0
 X(:)%Y(2) = 1.0 2.0 3.0
 CH(1:4) = "abcd"
 CH(1:4) = "abcd"
$END
$END
@end smallexample
@end smallexample
 
 
It should be noted that the default terminator is @samp{/} rather than
It should be noted that the default terminator is @samp{/} rather than
@samp{&END}.
@samp{&END}.
 
 
Querying of the namelist when inputting from stdin. After at least
Querying of the namelist when inputting from stdin. After at least
one space, entering @samp{?} sends to stdout the namelist name and the names of
one space, entering @samp{?} sends to stdout the namelist name and the names of
the variables in the namelist:
the variables in the namelist:
@smallexample
@smallexample
 ?
 ?
 
 
&mynml
&mynml
 x
 x
 x%y
 x%y
 ch
 ch
&end
&end
@end smallexample
@end smallexample
 
 
Entering @samp{=?} outputs the namelist to stdout, as if
Entering @samp{=?} outputs the namelist to stdout, as if
@code{WRITE(*,NML = mynml)} had been called:
@code{WRITE(*,NML = mynml)} had been called:
@smallexample
@smallexample
=?
=?
 
 
&MYNML
&MYNML
 X(1)%Y=  0.000000    ,  1.000000    ,  0.000000    ,
 X(1)%Y=  0.000000    ,  1.000000    ,  0.000000    ,
 X(2)%Y=  0.000000    ,  2.000000    ,  0.000000    ,
 X(2)%Y=  0.000000    ,  2.000000    ,  0.000000    ,
 X(3)%Y=  0.000000    ,  3.000000    ,  0.000000    ,
 X(3)%Y=  0.000000    ,  3.000000    ,  0.000000    ,
 CH=abcd,  /
 CH=abcd,  /
@end smallexample
@end smallexample
 
 
To aid this dialog, when input is from stdin, errors send their
To aid this dialog, when input is from stdin, errors send their
messages to stderr and execution continues, even if @code{IOSTAT} is set.
messages to stderr and execution continues, even if @code{IOSTAT} is set.
 
 
@code{PRINT} namelist is permitted.  This causes an error if
@code{PRINT} namelist is permitted.  This causes an error if
@option{-std=f95} is used.
@option{-std=f95} is used.
@smallexample
@smallexample
PROGRAM test_print
PROGRAM test_print
  REAL, dimension (4)  ::  x = (/1.0, 2.0, 3.0, 4.0/)
  REAL, dimension (4)  ::  x = (/1.0, 2.0, 3.0, 4.0/)
  NAMELIST /mynml/ x
  NAMELIST /mynml/ x
  PRINT mynml
  PRINT mynml
END PROGRAM test_print
END PROGRAM test_print
@end smallexample
@end smallexample
 
 
Expanded namelist reads are permitted.  This causes an error if
Expanded namelist reads are permitted.  This causes an error if
@option{-std=f95} is used.  In the following example, the first element
@option{-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
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.
elements will be given the values 1.00 and 2.00.
@smallexample
@smallexample
&MYNML
&MYNML
  X(1,1) = 0.00 , 1.00 , 2.00
  X(1,1) = 0.00 , 1.00 , 2.00
/
/
@end smallexample
@end smallexample
 
 
@node X format descriptor without count field
@node X format descriptor without count field
@subsection @code{X} format descriptor without count field
@subsection @code{X} format descriptor without count field
 
 
To support legacy codes, GNU Fortran permits the count field of the
To support legacy codes, GNU Fortran permits the count field of the
@code{X} edit descriptor in @code{FORMAT} statements to be omitted.
@code{X} edit descriptor in @code{FORMAT} statements to be omitted.
When omitted, the count is implicitly assumed to be one.
When omitted, the count is implicitly assumed to be one.
 
 
@smallexample
@smallexample
       PRINT 10, 2, 3
       PRINT 10, 2, 3
10     FORMAT (I1, X, I1)
10     FORMAT (I1, X, I1)
@end smallexample
@end smallexample
 
 
@node Commas in FORMAT specifications
@node Commas in FORMAT specifications
@subsection Commas in @code{FORMAT} specifications
@subsection Commas in @code{FORMAT} specifications
 
 
To support legacy codes, GNU Fortran allows the comma separator
To support legacy codes, GNU Fortran allows the comma separator
to be omitted immediately before and after character string edit
to be omitted immediately before and after character string edit
descriptors in @code{FORMAT} statements.
descriptors in @code{FORMAT} statements.
 
 
@smallexample
@smallexample
       PRINT 10, 2, 3
       PRINT 10, 2, 3
10     FORMAT ('FOO='I1' BAR='I2)
10     FORMAT ('FOO='I1' BAR='I2)
@end smallexample
@end smallexample
 
 
 
 
@node Missing period in FORMAT specifications
@node Missing period in FORMAT specifications
@subsection Missing period in @code{FORMAT} specifications
@subsection Missing period in @code{FORMAT} specifications
 
 
To support legacy codes, GNU Fortran allows missing periods in format
To support legacy codes, GNU Fortran allows missing periods in format
specifications if and only if @option{-std=legacy} is given on the
specifications if and only if @option{-std=legacy} is given on the
command line.  This is considered non-conforming code and is
command line.  This is considered non-conforming code and is
discouraged.
discouraged.
 
 
@smallexample
@smallexample
       REAL :: value
       REAL :: value
       READ(*,10) value
       READ(*,10) value
10     FORMAT ('F4')
10     FORMAT ('F4')
@end smallexample
@end smallexample
 
 
@node I/O item lists
@node I/O item lists
@subsection I/O item lists
@subsection I/O item lists
@cindex I/O item lists
@cindex I/O item lists
 
 
To support legacy codes, GNU Fortran allows the input item list
To support legacy codes, GNU Fortran allows the input item list
of the @code{READ} statement, and the output item lists of the
of the @code{READ} statement, and the output item lists of the
@code{WRITE} and @code{PRINT} statements, to start with a comma.
@code{WRITE} and @code{PRINT} statements, to start with a comma.
 
 
@node BOZ literal constants
@node BOZ literal constants
@subsection BOZ literal constants
@subsection BOZ literal constants
@cindex BOZ literal constants
@cindex BOZ literal constants
 
 
Besides decimal constants, Fortran also supports binary (@code{b}),
Besides decimal constants, Fortran also supports binary (@code{b}),
octal (@code{o}) and hexadecimal (@code{z}) integer constants. The
octal (@code{o}) and hexadecimal (@code{z}) integer constants. The
syntax is: @samp{prefix quote digits quote}, were the prefix is
syntax is: @samp{prefix quote digits quote}, were the prefix is
either @code{b}, @code{o} or @code{z}, quote is either @code{'} or
either @code{b}, @code{o} or @code{z}, quote is either @code{'} or
@code{"} and the digits are for binary @code{0} or @code{1}, for
@code{"} and the digits are for binary @code{0} or @code{1}, for
octal between @code{0} and @code{7}, and for hexadecimal between
octal between @code{0} and @code{7}, and for hexadecimal between
@code{0} and @code{F}. (Example: @code{b'01011101'}.)
@code{0} and @code{F}. (Example: @code{b'01011101'}.)
 
 
Up to Fortran 95, BOZ literals were only allowed to initialize
Up to Fortran 95, BOZ literals were only allowed to initialize
integer variables in DATA statements. Since Fortran 2003 BOZ literals
integer variables in DATA statements. Since Fortran 2003 BOZ literals
are also allowed as argument of @code{REAL}, @code{DBLE}, @code{INT}
are also allowed as argument of @code{REAL}, @code{DBLE}, @code{INT}
and @code{CMPLX}; the result is the same as if the integer BOZ
and @code{CMPLX}; the result is the same as if the integer BOZ
literal had been converted by @code{TRANSFER} to, respectively,
literal had been converted by @code{TRANSFER} to, respectively,
@code{real}, @code{double precision}, @code{integer} or @code{complex}.
@code{real}, @code{double precision}, @code{integer} or @code{complex}.
As GNU Fortran extension the intrinsic procedures @code{FLOAT},
As GNU Fortran extension the intrinsic procedures @code{FLOAT},
@code{DFLOAT}, @code{COMPLEX} and @code{DCMPLX} are treated alike.
@code{DFLOAT}, @code{COMPLEX} and @code{DCMPLX} are treated alike.
 
 
As an extension, GNU Fortran allows hexadecimal BOZ literal constants to
As an extension, GNU Fortran allows hexadecimal BOZ literal constants to
be specified using the @code{X} prefix, in addition to the standard
be specified using the @code{X} prefix, in addition to the standard
@code{Z} prefix. The BOZ literal can also be specified by adding a
@code{Z} prefix. The BOZ literal can also be specified by adding a
suffix to the string, for example, @code{Z'ABC'} and @code{'ABC'Z} are
suffix to the string, for example, @code{Z'ABC'} and @code{'ABC'Z} are
equivalent.
equivalent.
 
 
Furthermore, GNU Fortran allows using BOZ literal constants outside
Furthermore, GNU Fortran allows using BOZ literal constants outside
DATA statements and the four intrinsic functions allowed by Fortran 2003.
DATA statements and the four intrinsic functions allowed by Fortran 2003.
In DATA statements, in direct assignments, where the right-hand side
In DATA statements, in direct assignments, where the right-hand side
only contains a BOZ literal constant, and for old-style initializers of
only contains a BOZ literal constant, and for old-style initializers of
the form @code{integer i /o'0173'/}, the constant is transferred
the form @code{integer i /o'0173'/}, the constant is transferred
as if @code{TRANSFER} had been used; for @code{COMPLEX} numbers, only
as if @code{TRANSFER} had been used; for @code{COMPLEX} numbers, only
the real part is initialized unless @code{CMPLX} is used. In all other
the real part is initialized unless @code{CMPLX} is used. In all other
cases, the BOZ literal constant is converted to an @code{INTEGER} value with
cases, the BOZ literal constant is converted to an @code{INTEGER} value with
the largest decimal representation.  This value is then converted
the largest decimal representation.  This value is then converted
numerically to the type and kind of the variable in question.
numerically to the type and kind of the variable in question.
(For instance, @code{real :: r = b'0000001' + 1} initializes @code{r}
(For instance, @code{real :: r = b'0000001' + 1} initializes @code{r}
with @code{2.0}.) As different compilers implement the extension
with @code{2.0}.) As different compilers implement the extension
differently, one should be careful when doing bitwise initialization
differently, one should be careful when doing bitwise initialization
of non-integer variables.
of non-integer variables.
 
 
Note that initializing an @code{INTEGER} variable with a statement such
Note that initializing an @code{INTEGER} variable with a statement such
as @code{DATA i/Z'FFFFFFFF'/} will give an integer overflow error rather
as @code{DATA i/Z'FFFFFFFF'/} will give an integer overflow error rather
than the desired result of @math{-1} when @code{i} is a 32-bit integer
than the desired result of @math{-1} when @code{i} is a 32-bit integer
on a system that supports 64-bit integers.  The @samp{-fno-range-check}
on a system that supports 64-bit integers.  The @samp{-fno-range-check}
option can be used as a workaround for legacy code that initializes
option can be used as a workaround for legacy code that initializes
integers in this manner.
integers in this manner.
 
 
@node Real array indices
@node Real array indices
@subsection Real array indices
@subsection Real array indices
@cindex array, indices of type real
@cindex array, indices of type real
 
 
As an extension, GNU Fortran allows the use of @code{REAL} expressions
As an extension, GNU Fortran allows the use of @code{REAL} expressions
or variables as array indices.
or variables as array indices.
 
 
@node Unary operators
@node Unary operators
@subsection Unary operators
@subsection Unary operators
@cindex operators, unary
@cindex operators, unary
 
 
As an extension, GNU Fortran allows unary plus and unary minus operators
As an extension, GNU Fortran allows unary plus and unary minus operators
to appear as the second operand of binary arithmetic operators without
to appear as the second operand of binary arithmetic operators without
the need for parenthesis.
the need for parenthesis.
 
 
@smallexample
@smallexample
       X = Y * -Z
       X = Y * -Z
@end smallexample
@end smallexample
 
 
@node Implicitly convert LOGICAL and INTEGER values
@node Implicitly convert LOGICAL and INTEGER values
@subsection Implicitly convert @code{LOGICAL} and @code{INTEGER} values
@subsection Implicitly convert @code{LOGICAL} and @code{INTEGER} values
@cindex conversion, to integer
@cindex conversion, to integer
@cindex conversion, to logical
@cindex conversion, to logical
 
 
As an extension for backwards compatibility with other compilers, GNU
As an extension for backwards compatibility with other compilers, GNU
Fortran allows the implicit conversion of @code{LOGICAL} values to
Fortran allows the implicit conversion of @code{LOGICAL} values to
@code{INTEGER} values and vice versa.  When converting from a
@code{INTEGER} values and vice versa.  When converting from a
@code{LOGICAL} to an @code{INTEGER}, @code{.FALSE.} is interpreted as
@code{LOGICAL} to an @code{INTEGER}, @code{.FALSE.} is interpreted as
zero, and @code{.TRUE.} is interpreted as one.  When converting from
zero, and @code{.TRUE.} is interpreted as one.  When converting from
@code{INTEGER} to @code{LOGICAL}, the value zero is interpreted as
@code{INTEGER} to @code{LOGICAL}, the value zero is interpreted as
@code{.FALSE.} and any nonzero value is interpreted as @code{.TRUE.}.
@code{.FALSE.} and any nonzero value is interpreted as @code{.TRUE.}.
 
 
@smallexample
@smallexample
        LOGICAL :: l
        LOGICAL :: l
        l = 1
        l = 1
@end smallexample
@end smallexample
@smallexample
@smallexample
        INTEGER :: i
        INTEGER :: i
        i = .TRUE.
        i = .TRUE.
@end smallexample
@end smallexample
 
 
However, there is no implicit conversion of @code{INTEGER} values in
However, there is no implicit conversion of @code{INTEGER} values in
@code{if}-statements, nor of @code{LOGICAL} or @code{INTEGER} values
@code{if}-statements, nor of @code{LOGICAL} or @code{INTEGER} values
in I/O operations.
in I/O operations.
 
 
@node Hollerith constants support
@node Hollerith constants support
@subsection Hollerith constants support
@subsection Hollerith constants support
@cindex Hollerith constants
@cindex Hollerith constants
 
 
GNU Fortran supports Hollerith constants in assignments, function
GNU Fortran supports Hollerith constants in assignments, function
arguments, and @code{DATA} and @code{ASSIGN} statements.  A Hollerith
arguments, and @code{DATA} and @code{ASSIGN} statements.  A Hollerith
constant is written as a string of characters preceded by an integer
constant is written as a string of characters preceded by an integer
constant indicating the character count, and the letter @code{H} or
constant indicating the character count, and the letter @code{H} or
@code{h}, and stored in bytewise fashion in a numeric (@code{INTEGER},
@code{h}, and stored in bytewise fashion in a numeric (@code{INTEGER},
@code{REAL}, or @code{complex}) or @code{LOGICAL} variable.  The
@code{REAL}, or @code{complex}) or @code{LOGICAL} variable.  The
constant will be padded or truncated to fit the size of the variable in
constant will be padded or truncated to fit the size of the variable in
which it is stored.
which it is stored.
 
 
Examples of valid uses of Hollerith constants:
Examples of valid uses of Hollerith constants:
@smallexample
@smallexample
      complex*16 x(2)
      complex*16 x(2)
      data x /16Habcdefghijklmnop, 16Hqrstuvwxyz012345/
      data x /16Habcdefghijklmnop, 16Hqrstuvwxyz012345/
      x(1) = 16HABCDEFGHIJKLMNOP
      x(1) = 16HABCDEFGHIJKLMNOP
      call foo (4h abc)
      call foo (4h abc)
@end smallexample
@end smallexample
 
 
Invalid Hollerith constants examples:
Invalid Hollerith constants examples:
@smallexample
@smallexample
      integer*4 a
      integer*4 a
      a = 8H12345678 ! Valid, but the Hollerith constant will be truncated.
      a = 8H12345678 ! Valid, but the Hollerith constant will be truncated.
      a = 0H         ! At least one character is needed.
      a = 0H         ! At least one character is needed.
@end smallexample
@end smallexample
 
 
In general, Hollerith constants were used to provide a rudimentary
In general, Hollerith constants were used to provide a rudimentary
facility for handling character strings in early Fortran compilers,
facility for handling character strings in early Fortran compilers,
prior to the introduction of @code{CHARACTER} variables in Fortran 77;
prior to the introduction of @code{CHARACTER} variables in Fortran 77;
in those cases, the standard-compliant equivalent is to convert the
in those cases, the standard-compliant equivalent is to convert the
program to use proper character strings.  On occasion, there may be a
program to use proper character strings.  On occasion, there may be a
case where the intent is specifically to initialize a numeric variable
case where the intent is specifically to initialize a numeric variable
with a given byte sequence.  In these cases, the same result can be
with a given byte sequence.  In these cases, the same result can be
obtained by using the @code{TRANSFER} statement, as in this example.
obtained by using the @code{TRANSFER} statement, as in this example.
@smallexample
@smallexample
      INTEGER(KIND=4) :: a
      INTEGER(KIND=4) :: a
      a = TRANSFER ("abcd", a)     ! equivalent to: a = 4Habcd
      a = TRANSFER ("abcd", a)     ! equivalent to: a = 4Habcd
@end smallexample
@end smallexample
 
 
 
 
@node Cray pointers
@node Cray pointers
@subsection Cray pointers
@subsection Cray pointers
@cindex pointer, Cray
@cindex pointer, Cray
 
 
Cray pointers are part of a non-standard extension that provides a
Cray pointers are part of a non-standard extension that provides a
C-like pointer in Fortran.  This is accomplished through a pair of
C-like pointer in Fortran.  This is accomplished through a pair of
variables: an integer "pointer" that holds a memory address, and a
variables: an integer "pointer" that holds a memory address, and a
"pointee" that is used to dereference the pointer.
"pointee" that is used to dereference the pointer.
 
 
Pointer/pointee pairs are declared in statements of the form:
Pointer/pointee pairs are declared in statements of the form:
@smallexample
@smallexample
        pointer ( <pointer> , <pointee> )
        pointer ( <pointer> , <pointee> )
@end smallexample
@end smallexample
or,
or,
@smallexample
@smallexample
        pointer ( <pointer1> , <pointee1> ), ( <pointer2> , <pointee2> ), ...
        pointer ( <pointer1> , <pointee1> ), ( <pointer2> , <pointee2> ), ...
@end smallexample
@end smallexample
The pointer is an integer that is intended to hold a memory address.
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
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
size array---that is, the last dimension may be left unspecified by
using a @code{*} in place of a value---but a pointee cannot be an
using a @code{*} in place of a value---but a pointee cannot be an
assumed shape array.  No space is allocated for the pointee.
assumed shape array.  No space is allocated for the pointee.
 
 
The pointee may have its type declared before or after the pointer
The pointee may have its type declared before or after the pointer
statement, and its array specification (if any) may be declared
statement, and its array specification (if any) may be declared
before, during, or after the pointer statement.  The pointer may be
before, during, or after the pointer statement.  The pointer may be
declared as an integer prior to the pointer statement.  However, some
declared as an integer prior to the pointer statement.  However, some
machines have default integer sizes that are different than the size
machines have default integer sizes that are different than the size
of a pointer, and so the following code is not portable:
of a pointer, and so the following code is not portable:
@smallexample
@smallexample
        integer ipt
        integer ipt
        pointer (ipt, iarr)
        pointer (ipt, iarr)
@end smallexample
@end smallexample
If a pointer is declared with a kind that is too small, the compiler
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
will issue a warning; the resulting binary will probably not work
correctly, because the memory addresses stored in the pointers may be
correctly, because the memory addresses stored in the pointers may be
truncated.  It is safer to omit the first line of the above example;
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
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
will ensure that ipt is an integer variable large enough to hold a
pointer.
pointer.
 
 
Pointer arithmetic is valid with Cray pointers, but it is not the same
Pointer arithmetic is valid with Cray pointers, but it is not the same
as C pointer arithmetic.  Cray pointers are just ordinary integers, so
as C pointer arithmetic.  Cray pointers are just ordinary integers, so
the user is responsible for determining how many bytes to add to a
the user is responsible for determining how many bytes to add to a
pointer in order to increment it.  Consider the following example:
pointer in order to increment it.  Consider the following example:
@smallexample
@smallexample
        real target(10)
        real target(10)
        real pointee(10)
        real pointee(10)
        pointer (ipt, pointee)
        pointer (ipt, pointee)
        ipt = loc (target)
        ipt = loc (target)
        ipt = ipt + 1
        ipt = ipt + 1
@end smallexample
@end smallexample
The last statement does not set @code{ipt} to the address of
The last statement does not set @code{ipt} to the address of
@code{target(1)}, as it would in C pointer arithmetic.  Adding @code{1}
@code{target(1)}, as it would in C pointer arithmetic.  Adding @code{1}
to @code{ipt} just adds one byte to the address stored in @code{ipt}.
to @code{ipt} just adds one byte to the address stored in @code{ipt}.
 
 
Any expression involving the pointee will be translated to use the
Any expression involving the pointee will be translated to use the
value stored in the pointer as the base address.
value stored in the pointer as the base address.
 
 
To get the address of elements, this extension provides an intrinsic
To get the address of elements, this extension provides an intrinsic
function @code{LOC()}.  The @code{LOC()} function is equivalent to the
function @code{LOC()}.  The @code{LOC()} function is equivalent to the
@code{&} operator in C, except the address is cast to an integer type:
@code{&} operator in C, except the address is cast to an integer type:
@smallexample
@smallexample
        real ar(10)
        real ar(10)
        pointer(ipt, arpte(10))
        pointer(ipt, arpte(10))
        real arpte
        real arpte
        ipt = loc(ar)  ! Makes arpte is an alias for ar
        ipt = loc(ar)  ! Makes arpte is an alias for ar
        arpte(1) = 1.0 ! Sets ar(1) to 1.0
        arpte(1) = 1.0 ! Sets ar(1) to 1.0
@end smallexample
@end smallexample
The pointer can also be set by a call to the @code{MALLOC} intrinsic
The pointer can also be set by a call to the @code{MALLOC} intrinsic
(see @ref{MALLOC}).
(see @ref{MALLOC}).
 
 
Cray pointees often are used to alias an existing variable.  For
Cray pointees often are used to alias an existing variable.  For
example:
example:
@smallexample
@smallexample
        integer target(10)
        integer target(10)
        integer iarr(10)
        integer iarr(10)
        pointer (ipt, iarr)
        pointer (ipt, iarr)
        ipt = loc(target)
        ipt = loc(target)
@end smallexample
@end smallexample
As long as @code{ipt} remains unchanged, @code{iarr} is now an alias for
As long as @code{ipt} remains unchanged, @code{iarr} is now an alias for
@code{target}. The optimizer, however, will not detect this aliasing, so
@code{target}. The optimizer, however, will not detect this aliasing, so
it is unsafe to use @code{iarr} and @code{target} simultaneously.  Using
it is unsafe to use @code{iarr} and @code{target} simultaneously.  Using
a pointee in any way that violates the Fortran aliasing rules or
a pointee in any way that violates the Fortran aliasing rules or
assumptions is illegal. It is the user's responsibility to avoid doing
assumptions is illegal. It is the user's responsibility to avoid doing
this; the compiler works under the assumption that no such aliasing
this; the compiler works under the assumption that no such aliasing
occurs.
occurs.
 
 
Cray pointers will work correctly when there is no aliasing (i.e., when
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
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
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
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
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
that violates the aliasing rules is illegal.  (Note that this is not
unique to GNU Fortran; any Fortran compiler that supports Cray pointers
unique to GNU Fortran; any Fortran compiler that supports Cray pointers
will ``incorrectly'' optimize code with illegal aliasing.)
will ``incorrectly'' optimize code with illegal aliasing.)
 
 
There are a number of restrictions on the attributes that can be applied
There are a number of restrictions on the attributes that can be applied
to Cray pointers and pointees.  Pointees may not have the
to Cray pointers and pointees.  Pointees may not have the
@code{ALLOCATABLE}, @code{INTENT}, @code{OPTIONAL}, @code{DUMMY},
@code{ALLOCATABLE}, @code{INTENT}, @code{OPTIONAL}, @code{DUMMY},
@code{TARGET}, @code{INTRINSIC}, or @code{POINTER} attributes. Pointers
@code{TARGET}, @code{INTRINSIC}, or @code{POINTER} attributes. Pointers
may not have the @code{DIMENSION}, @code{POINTER}, @code{TARGET},
may not have the @code{DIMENSION}, @code{POINTER}, @code{TARGET},
@code{ALLOCATABLE}, @code{EXTERNAL}, or @code{INTRINSIC} attributes.
@code{ALLOCATABLE}, @code{EXTERNAL}, or @code{INTRINSIC} attributes.
Pointees may not occur in more than one pointer statement.  A pointee
Pointees may not occur in more than one pointer statement.  A pointee
cannot be a pointer.  Pointees cannot occur in equivalence, common, or
cannot be a pointer.  Pointees cannot occur in equivalence, common, or
data statements.
data statements.
 
 
A Cray pointer may also point to a function or a subroutine.  For
A Cray pointer may also point to a function or a subroutine.  For
example, the following excerpt is valid:
example, the following excerpt is valid:
@smallexample
@smallexample
  implicit none
  implicit none
  external sub
  external sub
  pointer (subptr,subpte)
  pointer (subptr,subpte)
  external subpte
  external subpte
  subptr = loc(sub)
  subptr = loc(sub)
  call subpte()
  call subpte()
  [...]
  [...]
  subroutine sub
  subroutine sub
  [...]
  [...]
  end subroutine sub
  end subroutine sub
@end smallexample
@end smallexample
 
 
A pointer may be modified during the course of a program, and this
A pointer may be modified during the course of a program, and this
will change the location to which the pointee refers.  However, when
will change the location to which the pointee refers.  However, when
pointees are passed as arguments, they are treated as ordinary
pointees are passed as arguments, they are treated as ordinary
variables in the invoked function.  Subsequent changes to the pointer
variables in the invoked function.  Subsequent changes to the pointer
will not change the base address of the array that was passed.
will not change the base address of the array that was passed.
 
 
@node CONVERT specifier
@node CONVERT specifier
@subsection @code{CONVERT} specifier
@subsection @code{CONVERT} specifier
@cindex @code{CONVERT} specifier
@cindex @code{CONVERT} specifier
 
 
GNU Fortran allows the conversion of unformatted data between little-
GNU Fortran allows the conversion of unformatted data between little-
and big-endian representation to facilitate moving of data
and big-endian representation to facilitate moving of data
between different systems.  The conversion can be indicated with
between different systems.  The conversion can be indicated with
the @code{CONVERT} specifier on the @code{OPEN} statement.
the @code{CONVERT} specifier on the @code{OPEN} statement.
@xref{GFORTRAN_CONVERT_UNIT}, for an alternative way of specifying
@xref{GFORTRAN_CONVERT_UNIT}, for an alternative way of specifying
the data format via an environment variable.
the data format via an environment variable.
 
 
Valid values for @code{CONVERT} are:
Valid values for @code{CONVERT} are:
@itemize @w{}
@itemize @w{}
@item @code{CONVERT='NATIVE'} Use the native format.  This is the default.
@item @code{CONVERT='NATIVE'} Use the native format.  This is the default.
@item @code{CONVERT='SWAP'} Swap between little- and big-endian.
@item @code{CONVERT='SWAP'} Swap between little- and big-endian.
@item @code{CONVERT='LITTLE_ENDIAN'} Use the little-endian representation
@item @code{CONVERT='LITTLE_ENDIAN'} Use the little-endian representation
for unformatted files.
for unformatted files.
@item @code{CONVERT='BIG_ENDIAN'} Use the big-endian representation for
@item @code{CONVERT='BIG_ENDIAN'} Use the big-endian representation for
unformatted files.
unformatted files.
@end itemize
@end itemize
 
 
Using the option could look like this:
Using the option could look like this:
@smallexample
@smallexample
  open(file='big.dat',form='unformatted',access='sequential', &
  open(file='big.dat',form='unformatted',access='sequential', &
       convert='big_endian')
       convert='big_endian')
@end smallexample
@end smallexample
 
 
The value of the conversion can be queried by using
The value of the conversion can be queried by using
@code{INQUIRE(CONVERT=ch)}.  The values returned are
@code{INQUIRE(CONVERT=ch)}.  The values returned are
@code{'BIG_ENDIAN'} and @code{'LITTLE_ENDIAN'}.
@code{'BIG_ENDIAN'} and @code{'LITTLE_ENDIAN'}.
 
 
@code{CONVERT} works between big- and little-endian for
@code{CONVERT} works between big- and little-endian for
@code{INTEGER} values of all supported kinds and for @code{REAL}
@code{INTEGER} values of all supported kinds and for @code{REAL}
on IEEE systems of kinds 4 and 8.  Conversion between different
on IEEE systems of kinds 4 and 8.  Conversion between different
``extended double'' types on different architectures such as
``extended double'' types on different architectures such as
m68k and x86_64, which GNU Fortran
m68k and x86_64, which GNU Fortran
supports as @code{REAL(KIND=10)} and @code{REAL(KIND=16)}, will
supports as @code{REAL(KIND=10)} and @code{REAL(KIND=16)}, will
probably not work.
probably not work.
 
 
@emph{Note that the values specified via the GFORTRAN_CONVERT_UNIT
@emph{Note that the values specified via the GFORTRAN_CONVERT_UNIT
environment variable will override the CONVERT specifier in the
environment variable will override the CONVERT specifier in the
open statement}.  This is to give control over data formats to
open statement}.  This is to give control over data formats to
users who do not have the source code of their program available.
users who do not have the source code of their program available.
 
 
Using anything but the native representation for unformatted data
Using anything but the native representation for unformatted data
carries a significant speed overhead.  If speed in this area matters
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
to you, it is best if you use this only for data that needs to be
portable.
portable.
 
 
@node OpenMP
@node OpenMP
@subsection OpenMP
@subsection OpenMP
@cindex OpenMP
@cindex OpenMP
 
 
OpenMP (Open Multi-Processing) is an application programming
OpenMP (Open Multi-Processing) is an application programming
interface (API) that supports multi-platform shared memory
interface (API) that supports multi-platform shared memory
multiprocessing programming in C/C++ and Fortran on many
multiprocessing programming in C/C++ and Fortran on many
architectures, including Unix and Microsoft Windows platforms.
architectures, including Unix and Microsoft Windows platforms.
It consists of a set of compiler directives, library routines,
It consists of a set of compiler directives, library routines,
and environment variables that influence run-time behavior.
and environment variables that influence run-time behavior.
 
 
GNU Fortran strives to be compatible to the
GNU Fortran strives to be compatible to the
@uref{http://www.openmp.org/mp-documents/spec30.pdf,
@uref{http://www.openmp.org/mp-documents/spec30.pdf,
OpenMP Application Program Interface v3.0}.
OpenMP Application Program Interface v3.0}.
 
 
To enable the processing of the OpenMP directive @code{!$omp} in
To enable the processing of the OpenMP directive @code{!$omp} in
free-form source code; the @code{c$omp}, @code{*$omp} and @code{!$omp}
free-form source code; the @code{c$omp}, @code{*$omp} and @code{!$omp}
directives in fixed form; the @code{!$} conditional compilation sentinels
directives in fixed form; the @code{!$} conditional compilation sentinels
in free form; and the @code{c$}, @code{*$} and @code{!$} sentinels
in free form; and the @code{c$}, @code{*$} and @code{!$} sentinels
in fixed form, @command{gfortran} needs to be invoked with the
in fixed form, @command{gfortran} needs to be invoked with the
@option{-fopenmp}. This also arranges for automatic linking of the
@option{-fopenmp}. This also arranges for automatic linking of the
GNU OpenMP runtime library @ref{Top,,libgomp,libgomp,GNU OpenMP
GNU OpenMP runtime library @ref{Top,,libgomp,libgomp,GNU OpenMP
runtime library}.
runtime library}.
 
 
The OpenMP Fortran runtime library routines are provided both in a
The OpenMP Fortran runtime library routines are provided both in a
form of a Fortran 90 module named @code{omp_lib} and in a form of
form of a Fortran 90 module named @code{omp_lib} and in a form of
a Fortran @code{include} file named @file{omp_lib.h}.
a Fortran @code{include} file named @file{omp_lib.h}.
 
 
An example of a parallelized loop taken from Appendix A.1 of
An example of a parallelized loop taken from Appendix A.1 of
the OpenMP Application Program Interface v2.5:
the OpenMP Application Program Interface v2.5:
@smallexample
@smallexample
SUBROUTINE A1(N, A, B)
SUBROUTINE A1(N, A, B)
  INTEGER I, N
  INTEGER I, N
  REAL B(N), A(N)
  REAL B(N), A(N)
!$OMP PARALLEL DO !I is private by default
!$OMP PARALLEL DO !I is private by default
  DO I=2,N
  DO I=2,N
    B(I) = (A(I) + A(I-1)) / 2.0
    B(I) = (A(I) + A(I-1)) / 2.0
  ENDDO
  ENDDO
!$OMP END PARALLEL DO
!$OMP END PARALLEL DO
END SUBROUTINE A1
END SUBROUTINE A1
@end smallexample
@end smallexample
 
 
Please note:
Please note:
@itemize
@itemize
@item
@item
@option{-fopenmp} implies @option{-frecursive}, i.e., all local arrays
@option{-fopenmp} implies @option{-frecursive}, i.e., all local arrays
will be allocated on the stack. When porting existing code to OpenMP,
will be allocated on the stack. When porting existing code to OpenMP,
this may lead to surprising results, especially to segmentation faults
this may lead to surprising results, especially to segmentation faults
if the stacksize is limited.
if the stacksize is limited.
 
 
@item
@item
On glibc-based systems, OpenMP enabled applications cannot be statically
On glibc-based systems, OpenMP enabled applications cannot be statically
linked due to limitations of the underlying pthreads-implementation. It
linked due to limitations of the underlying pthreads-implementation. It
might be possible to get a working solution if
might be possible to get a working solution if
@command{-Wl,--whole-archive -lpthread -Wl,--no-whole-archive} is added
@command{-Wl,--whole-archive -lpthread -Wl,--no-whole-archive} is added
to the command line. However, this is not supported by @command{gcc} and
to the command line. However, this is not supported by @command{gcc} and
thus not recommended.
thus not recommended.
@end itemize
@end itemize
 
 
@node Argument list functions
@node Argument list functions
@subsection Argument list functions @code{%VAL}, @code{%REF} and @code{%LOC}
@subsection Argument list functions @code{%VAL}, @code{%REF} and @code{%LOC}
@cindex argument list functions
@cindex argument list functions
@cindex @code{%VAL}
@cindex @code{%VAL}
@cindex @code{%REF}
@cindex @code{%REF}
@cindex @code{%LOC}
@cindex @code{%LOC}
 
 
GNU Fortran supports argument list functions @code{%VAL}, @code{%REF}
GNU Fortran supports argument list functions @code{%VAL}, @code{%REF}
and @code{%LOC} statements, for backward compatibility with g77.
and @code{%LOC} statements, for backward compatibility with g77.
It is recommended that these should be used only for code that is
It is recommended that these should be used only for code that is
accessing facilities outside of GNU Fortran, such as operating system
accessing facilities outside of GNU Fortran, such as operating system
or windowing facilities. It is best to constrain such uses to isolated
or windowing facilities. It is best to constrain such uses to isolated
portions of a program--portions that deal specifically and exclusively
portions of a program--portions that deal specifically and exclusively
with low-level, system-dependent facilities. Such portions might well
with low-level, system-dependent facilities. Such portions might well
provide a portable interface for use by the program as a whole, but are
provide a portable interface for use by the program as a whole, but are
themselves not portable, and should be thoroughly tested each time they
themselves not portable, and should be thoroughly tested each time they
are rebuilt using a new compiler or version of a compiler.
are rebuilt using a new compiler or version of a compiler.
 
 
@code{%VAL} passes a scalar argument by value, @code{%REF} passes it by
@code{%VAL} passes a scalar argument by value, @code{%REF} passes it by
reference and @code{%LOC} passes its memory location.  Since gfortran
reference and @code{%LOC} passes its memory location.  Since gfortran
already passes scalar arguments by reference, @code{%REF} is in effect
already passes scalar arguments by reference, @code{%REF} is in effect
a do-nothing.  @code{%LOC} has the same effect as a Fortran pointer.
a do-nothing.  @code{%LOC} has the same effect as a Fortran pointer.
 
 
An example of passing an argument by value to a C subroutine foo.:
An example of passing an argument by value to a C subroutine foo.:
@smallexample
@smallexample
C
C
C prototype      void foo_ (float x);
C prototype      void foo_ (float x);
C
C
      external foo
      external foo
      real*4 x
      real*4 x
      x = 3.14159
      x = 3.14159
      call foo (%VAL (x))
      call foo (%VAL (x))
      end
      end
@end smallexample
@end smallexample
 
 
For details refer to the g77 manual
For details refer to the g77 manual
@uref{http://gcc.gnu.org/onlinedocs/gcc-3.4.6/g77/index.html#Top}.
@uref{http://gcc.gnu.org/onlinedocs/gcc-3.4.6/g77/index.html#Top}.
 
 
Also, @code{c_by_val.f} and its partner @code{c_by_val.c} of the
Also, @code{c_by_val.f} and its partner @code{c_by_val.c} of the
GNU Fortran testsuite are worth a look.
GNU Fortran testsuite are worth a look.
 
 
 
 
@node Extensions not implemented in GNU Fortran
@node Extensions not implemented in GNU Fortran
@section Extensions not implemented in GNU Fortran
@section Extensions not implemented in GNU Fortran
@cindex extensions, not implemented
@cindex extensions, not implemented
 
 
The long history of the Fortran language, its wide use and broad
The long history of the Fortran language, its wide use and broad
userbase, the large number of different compiler vendors and the lack of
userbase, the large number of different compiler vendors and the lack of
some features crucial to users in the first standards have lead to the
some features crucial to users in the first standards have lead to the
existence of a number of important extensions to the language.  While
existence of a number of important extensions to the language.  While
some of the most useful or popular extensions are supported by the GNU
some of the most useful or popular extensions are supported by the GNU
Fortran compiler, not all existing extensions are supported.  This section
Fortran compiler, not all existing extensions are supported.  This section
aims at listing these extensions and offering advice on how best make
aims at listing these extensions and offering advice on how best make
code that uses them running with the GNU Fortran compiler.
code that uses them running with the GNU Fortran compiler.
 
 
@c More can be found here:
@c More can be found here:
@c   -- http://gcc.gnu.org/onlinedocs/gcc-3.4.6/g77/Missing-Features.html
@c   -- http://gcc.gnu.org/onlinedocs/gcc-3.4.6/g77/Missing-Features.html
@c   -- the list of Fortran and libgfortran bugs closed as WONTFIX:
@c   -- the list of Fortran and libgfortran bugs closed as WONTFIX:
@c      http://tinyurl.com/2u4h5y
@c      http://tinyurl.com/2u4h5y
 
 
@menu
@menu
* STRUCTURE and RECORD::
* STRUCTURE and RECORD::
@c * UNION and MAP::
@c * UNION and MAP::
* ENCODE and DECODE statements::
* ENCODE and DECODE statements::
* Variable FORMAT expressions::
* Variable FORMAT expressions::
@c * Q edit descriptor::
@c * Q edit descriptor::
@c * AUTOMATIC statement::
@c * AUTOMATIC statement::
@c * TYPE and ACCEPT I/O Statements::
@c * TYPE and ACCEPT I/O Statements::
@c * .XOR. operator::
@c * .XOR. operator::
@c * CARRIAGECONTROL, DEFAULTFILE, DISPOSE and RECORDTYPE I/O specifiers::
@c * CARRIAGECONTROL, DEFAULTFILE, DISPOSE and RECORDTYPE I/O specifiers::
@c * Omitted arguments in procedure call:
@c * Omitted arguments in procedure call:
@end menu
@end menu
 
 
 
 
@node STRUCTURE and RECORD
@node STRUCTURE and RECORD
@subsection @code{STRUCTURE} and @code{RECORD}
@subsection @code{STRUCTURE} and @code{RECORD}
@cindex @code{STRUCTURE}
@cindex @code{STRUCTURE}
@cindex @code{RECORD}
@cindex @code{RECORD}
 
 
Structures are user-defined aggregate data types; this functionality was
Structures are user-defined aggregate data types; this functionality was
standardized in Fortran 90 with an different syntax, under the name of
standardized in Fortran 90 with an different syntax, under the name of
``derived types''. Here is an example of code using the non portable
``derived types''. Here is an example of code using the non portable
structure syntax:
structure syntax:
 
 
@example
@example
! Declaring a structure named ``item'' and containing three fields:
! Declaring a structure named ``item'' and containing three fields:
! an integer ID, an description string and a floating-point price.
! an integer ID, an description string and a floating-point price.
STRUCTURE /item/
STRUCTURE /item/
  INTEGER id
  INTEGER id
  CHARACTER(LEN=200) description
  CHARACTER(LEN=200) description
  REAL price
  REAL price
END STRUCTURE
END STRUCTURE
 
 
! Define two variables, an single record of type ``item''
! Define two variables, an single record of type ``item''
! named ``pear'', and an array of items named ``store_catalog''
! named ``pear'', and an array of items named ``store_catalog''
RECORD /item/ pear, store_catalog(100)
RECORD /item/ pear, store_catalog(100)
 
 
! We can directly access the fields of both variables
! We can directly access the fields of both variables
pear.id = 92316
pear.id = 92316
pear.description = "juicy D'Anjou pear"
pear.description = "juicy D'Anjou pear"
pear.price = 0.15
pear.price = 0.15
store_catalog(7).id = 7831
store_catalog(7).id = 7831
store_catalog(7).description = "milk bottle"
store_catalog(7).description = "milk bottle"
store_catalog(7).price = 1.2
store_catalog(7).price = 1.2
 
 
! We can also manipulate the whole structure
! We can also manipulate the whole structure
store_catalog(12) = pear
store_catalog(12) = pear
print *, store_catalog(12)
print *, store_catalog(12)
@end example
@end example
 
 
@noindent
@noindent
This code can easily be rewritten in the Fortran 90 syntax as following:
This code can easily be rewritten in the Fortran 90 syntax as following:
 
 
@example
@example
! ``STRUCTURE /name/ ... END STRUCTURE'' becomes
! ``STRUCTURE /name/ ... END STRUCTURE'' becomes
! ``TYPE name ... END TYPE''
! ``TYPE name ... END TYPE''
TYPE item
TYPE item
  INTEGER id
  INTEGER id
  CHARACTER(LEN=200) description
  CHARACTER(LEN=200) description
  REAL price
  REAL price
END TYPE
END TYPE
 
 
! ``RECORD /name/ variable'' becomes ``TYPE(name) variable''
! ``RECORD /name/ variable'' becomes ``TYPE(name) variable''
TYPE(item) pear, store_catalog(100)
TYPE(item) pear, store_catalog(100)
 
 
! Instead of using a dot (.) to access fields of a record, the
! Instead of using a dot (.) to access fields of a record, the
! standard syntax uses a percent sign (%)
! standard syntax uses a percent sign (%)
pear%id = 92316
pear%id = 92316
pear%description = "juicy D'Anjou pear"
pear%description = "juicy D'Anjou pear"
pear%price = 0.15
pear%price = 0.15
store_catalog(7)%id = 7831
store_catalog(7)%id = 7831
store_catalog(7)%description = "milk bottle"
store_catalog(7)%description = "milk bottle"
store_catalog(7)%price = 1.2
store_catalog(7)%price = 1.2
 
 
! Assignments of a whole variable don't change
! Assignments of a whole variable don't change
store_catalog(12) = pear
store_catalog(12) = pear
print *, store_catalog(12)
print *, store_catalog(12)
@end example
@end example
 
 
 
 
@c @node UNION and MAP
@c @node UNION and MAP
@c @subsection @code{UNION} and @code{MAP}
@c @subsection @code{UNION} and @code{MAP}
@c @cindex @code{UNION}
@c @cindex @code{UNION}
@c @cindex @code{MAP}
@c @cindex @code{MAP}
@c
@c
@c For help writing this one, see
@c For help writing this one, see
@c http://www.eng.umd.edu/~nsw/ench250/fortran1.htm#UNION and
@c http://www.eng.umd.edu/~nsw/ench250/fortran1.htm#UNION and
@c http://www.tacc.utexas.edu/services/userguides/pgi/pgiws_ug/pgi32u06.htm
@c http://www.tacc.utexas.edu/services/userguides/pgi/pgiws_ug/pgi32u06.htm
 
 
 
 
@node ENCODE and DECODE statements
@node ENCODE and DECODE statements
@subsection @code{ENCODE} and @code{DECODE} statements
@subsection @code{ENCODE} and @code{DECODE} statements
@cindex @code{ENCODE}
@cindex @code{ENCODE}
@cindex @code{DECODE}
@cindex @code{DECODE}
 
 
GNU Fortran doesn't support the @code{ENCODE} and @code{DECODE}
GNU Fortran doesn't support the @code{ENCODE} and @code{DECODE}
statements.  These statements are best replaced by @code{READ} and
statements.  These statements are best replaced by @code{READ} and
@code{WRITE} statements involving internal files (@code{CHARACTER}
@code{WRITE} statements involving internal files (@code{CHARACTER}
variables and arrays), which have been part of the Fortran standard since
variables and arrays), which have been part of the Fortran standard since
Fortran 77. For example, replace a code fragment like
Fortran 77. For example, replace a code fragment like
 
 
@smallexample
@smallexample
      INTEGER*1 LINE(80)
      INTEGER*1 LINE(80)
      REAL A, B, C
      REAL A, B, C
c     ... Code that sets LINE
c     ... Code that sets LINE
      DECODE (80, 9000, LINE) A, B, C
      DECODE (80, 9000, LINE) A, B, C
 9000 FORMAT (1X, 3(F10.5))
 9000 FORMAT (1X, 3(F10.5))
@end smallexample
@end smallexample
 
 
@noindent
@noindent
with the following:
with the following:
 
 
@smallexample
@smallexample
      CHARACTER(LEN=80) LINE
      CHARACTER(LEN=80) LINE
      REAL A, B, C
      REAL A, B, C
c     ... Code that sets LINE
c     ... Code that sets LINE
      READ (UNIT=LINE, FMT=9000) A, B, C
      READ (UNIT=LINE, FMT=9000) A, B, C
 9000 FORMAT (1X, 3(F10.5))
 9000 FORMAT (1X, 3(F10.5))
@end smallexample
@end smallexample
 
 
Similarly, replace a code fragment like
Similarly, replace a code fragment like
 
 
@smallexample
@smallexample
      INTEGER*1 LINE(80)
      INTEGER*1 LINE(80)
      REAL A, B, C
      REAL A, B, C
c     ... Code that sets A, B and C
c     ... Code that sets A, B and C
      ENCODE (80, 9000, LINE) A, B, C
      ENCODE (80, 9000, LINE) A, B, C
 9000 FORMAT (1X, 'OUTPUT IS ', 3(F10.5))
 9000 FORMAT (1X, 'OUTPUT IS ', 3(F10.5))
@end smallexample
@end smallexample
 
 
@noindent
@noindent
with the following:
with the following:
 
 
@smallexample
@smallexample
      CHARACTER(LEN=80) LINE
      CHARACTER(LEN=80) LINE
      REAL A, B, C
      REAL A, B, C
c     ... Code that sets A, B and C
c     ... Code that sets A, B and C
      WRITE (UNIT=LINE, FMT=9000) A, B, C
      WRITE (UNIT=LINE, FMT=9000) A, B, C
 9000 FORMAT (1X, 'OUTPUT IS ', 3(F10.5))
 9000 FORMAT (1X, 'OUTPUT IS ', 3(F10.5))
@end smallexample
@end smallexample
 
 
 
 
@node Variable FORMAT expressions
@node Variable FORMAT expressions
@subsection Variable @code{FORMAT} expressions
@subsection Variable @code{FORMAT} expressions
@cindex @code{FORMAT}
@cindex @code{FORMAT}
 
 
A variable @code{FORMAT} expression is format statement which includes
A variable @code{FORMAT} expression is format statement which includes
angle brackets enclosing a Fortran expression: @code{FORMAT(I<N>)}. GNU
angle brackets enclosing a Fortran expression: @code{FORMAT(I<N>)}. GNU
Fortran does not support this legacy extension. The effect of variable
Fortran does not support this legacy extension. The effect of variable
format expressions can be reproduced by using the more powerful (and
format expressions can be reproduced by using the more powerful (and
standard) combination of internal output and string formats. For example,
standard) combination of internal output and string formats. For example,
replace a code fragment like this:
replace a code fragment like this:
 
 
@smallexample
@smallexample
      WRITE(6,20) INT1
      WRITE(6,20) INT1
 20   FORMAT(I<N+1>)
 20   FORMAT(I<N+1>)
@end smallexample
@end smallexample
 
 
@noindent
@noindent
with the following:
with the following:
 
 
@smallexample
@smallexample
c     Variable declaration
c     Variable declaration
      CHARACTER(LEN=20) F
      CHARACTER(LEN=20) F
c
c
c     Other code here...
c     Other code here...
c
c
      WRITE(FMT,'("(I", I0, ")")') N+1
      WRITE(FMT,'("(I", I0, ")")') N+1
      WRITE(6,FM) INT1
      WRITE(6,FM) INT1
@end smallexample
@end smallexample
 
 
@noindent
@noindent
or with:
or with:
 
 
@smallexample
@smallexample
c     Variable declaration
c     Variable declaration
      CHARACTER(LEN=20) FMT
      CHARACTER(LEN=20) FMT
c
c
c     Other code here...
c     Other code here...
c
c
      WRITE(FMT,*) N+1
      WRITE(FMT,*) N+1
      WRITE(6,"(I" // ADJUSTL(FMT) // ")") INT1
      WRITE(6,"(I" // ADJUSTL(FMT) // ")") INT1
@end smallexample
@end smallexample
 
 
 
 
@c ---------------------------------------------------------------------
@c ---------------------------------------------------------------------
@c Mixed-Language Programming
@c Mixed-Language Programming
@c ---------------------------------------------------------------------
@c ---------------------------------------------------------------------
 
 
@node Mixed-Language Programming
@node Mixed-Language Programming
@chapter Mixed-Language Programming
@chapter Mixed-Language Programming
@cindex Interoperability
@cindex Interoperability
@cindex Mixed-language programming
@cindex Mixed-language programming
 
 
@menu
@menu
* Interoperability with C::
* Interoperability with C::
* GNU Fortran Compiler Directives::
* GNU Fortran Compiler Directives::
* Non-Fortran Main Program::
* Non-Fortran Main Program::
@end menu
@end menu
 
 
This chapter is about mixed-language interoperability, but also applies
This chapter is about mixed-language interoperability, but also applies
if one links Fortran code compiled by different compilers. In most cases,
if one links Fortran code compiled by different compilers. In most cases,
use of the C Binding features of the Fortran 2003 standard is sufficient,
use of the C Binding features of the Fortran 2003 standard is sufficient,
and their use is highly recommended.
and their use is highly recommended.
 
 
 
 
@node Interoperability with C
@node Interoperability with C
@section Interoperability with C
@section Interoperability with C
 
 
@menu
@menu
* Intrinsic Types::
* Intrinsic Types::
* Further Interoperability of Fortran with C::
* Further Interoperability of Fortran with C::
* Derived Types and struct::
* Derived Types and struct::
* Interoperable Global Variables::
* Interoperable Global Variables::
* Interoperable Subroutines and Functions::
* Interoperable Subroutines and Functions::
@end menu
@end menu
 
 
Since Fortran 2003 (ISO/IEC 1539-1:2004(E)) there is a
Since Fortran 2003 (ISO/IEC 1539-1:2004(E)) there is a
standardized way to generate procedure and derived-type
standardized way to generate procedure and derived-type
declarations and global variables which are interoperable with C
declarations and global variables which are interoperable with C
(ISO/IEC 9899:1999). The @code{bind(C)} attribute has been added
(ISO/IEC 9899:1999). The @code{bind(C)} attribute has been added
to inform the compiler that a symbol shall be interoperable with C;
to inform the compiler that a symbol shall be interoperable with C;
also, some constraints are added. Note, however, that not
also, some constraints are added. Note, however, that not
all C features have a Fortran equivalent or vice versa. For instance,
all C features have a Fortran equivalent or vice versa. For instance,
neither C's unsigned integers nor C's functions with variable number
neither C's unsigned integers nor C's functions with variable number
of arguments have an equivalent in Fortran.
of arguments have an equivalent in Fortran.
 
 
Note that array dimensions are reversely ordered in C and that arrays in
Note that array dimensions are reversely ordered in C and that arrays in
C always start with index 0 while in Fortran they start by default with
C always start with index 0 while in Fortran they start by default with
1. Thus, an array declaration @code{A(n,m)} in Fortran matches
1. Thus, an array declaration @code{A(n,m)} in Fortran matches
@code{A[m][n]} in C and accessing the element @code{A(i,j)} matches
@code{A[m][n]} in C and accessing the element @code{A(i,j)} matches
@code{A[j-1][i-1]}. The element following @code{A(i,j)} (C: @code{A[j-1][i-1]};
@code{A[j-1][i-1]}. The element following @code{A(i,j)} (C: @code{A[j-1][i-1]};
assuming @math{i < n}) in memory is @code{A(i+1,j)} (C: @code{A[j-1][i]}).
assuming @math{i < n}) in memory is @code{A(i+1,j)} (C: @code{A[j-1][i]}).
 
 
@node Intrinsic Types
@node Intrinsic Types
@subsection Intrinsic Types
@subsection Intrinsic Types
 
 
In order to ensure that exactly the same variable type and kind is used
In order to ensure that exactly the same variable type and kind is used
in C and Fortran, the named constants shall be used which are defined in the
in C and Fortran, the named constants shall be used which are defined in the
@code{ISO_C_BINDING} intrinsic module. That module contains named constants
@code{ISO_C_BINDING} intrinsic module. That module contains named constants
for kind parameters and character named constants for the escape sequences
for kind parameters and character named constants for the escape sequences
in C. For a list of the constants, see @ref{ISO_C_BINDING}.
in C. For a list of the constants, see @ref{ISO_C_BINDING}.
 
 
@node Derived Types and struct
@node Derived Types and struct
@subsection Derived Types and struct
@subsection Derived Types and struct
 
 
For compatibility of derived types with @code{struct}, one needs to use
For compatibility of derived types with @code{struct}, one needs to use
the @code{BIND(C)} attribute in the type declaration. For instance, the
the @code{BIND(C)} attribute in the type declaration. For instance, the
following type declaration
following type declaration
 
 
@smallexample
@smallexample
 USE ISO_C_BINDING
 USE ISO_C_BINDING
 TYPE, BIND(C) :: myType
 TYPE, BIND(C) :: myType
   INTEGER(C_INT) :: i1, i2
   INTEGER(C_INT) :: i1, i2
   INTEGER(C_SIGNED_CHAR) :: i3
   INTEGER(C_SIGNED_CHAR) :: i3
   REAL(C_DOUBLE) :: d1
   REAL(C_DOUBLE) :: d1
   COMPLEX(C_FLOAT_COMPLEX) :: c1
   COMPLEX(C_FLOAT_COMPLEX) :: c1
   CHARACTER(KIND=C_CHAR) :: str(5)
   CHARACTER(KIND=C_CHAR) :: str(5)
 END TYPE
 END TYPE
@end smallexample
@end smallexample
 
 
matches the following @code{struct} declaration in C
matches the following @code{struct} declaration in C
 
 
@smallexample
@smallexample
 struct @{
 struct @{
   int i1, i2;
   int i1, i2;
   /* Note: "char" might be signed or unsigned.  */
   /* Note: "char" might be signed or unsigned.  */
   signed char i3;
   signed char i3;
   double d1;
   double d1;
   float _Complex c1;
   float _Complex c1;
   char str[5];
   char str[5];
 @} myType;
 @} myType;
@end smallexample
@end smallexample
 
 
Derived types with the C binding attribute shall not have the @code{sequence}
Derived types with the C binding attribute shall not have the @code{sequence}
attribute, type parameters, the @code{extends} attribute, nor type-bound
attribute, type parameters, the @code{extends} attribute, nor type-bound
procedures. Every component must be of interoperable type and kind and may not
procedures. Every component must be of interoperable type and kind and may not
have the @code{pointer} or @code{allocatable} attribute. The names of the
have the @code{pointer} or @code{allocatable} attribute. The names of the
variables are irrelevant for interoperability.
variables are irrelevant for interoperability.
 
 
As there exist no direct Fortran equivalents, neither unions nor structs
As there exist no direct Fortran equivalents, neither unions nor structs
with bit field or variable-length array members are interoperable.
with bit field or variable-length array members are interoperable.
 
 
@node Interoperable Global Variables
@node Interoperable Global Variables
@subsection Interoperable Global Variables
@subsection Interoperable Global Variables
 
 
Variables can be made accessible from C using the C binding attribute,
Variables can be made accessible from C using the C binding attribute,
optionally together with specifying a binding name. Those variables
optionally together with specifying a binding name. Those variables
have to be declared in the declaration part of a @code{MODULE},
have to be declared in the declaration part of a @code{MODULE},
be of interoperable type, and have neither the @code{pointer} nor
be of interoperable type, and have neither the @code{pointer} nor
the @code{allocatable} attribute.
the @code{allocatable} attribute.
 
 
@smallexample
@smallexample
  MODULE m
  MODULE m
    USE myType_module
    USE myType_module
    USE ISO_C_BINDING
    USE ISO_C_BINDING
    integer(C_INT), bind(C, name="_MyProject_flags") :: global_flag
    integer(C_INT), bind(C, name="_MyProject_flags") :: global_flag
    type(myType), bind(C) :: tp
    type(myType), bind(C) :: tp
  END MODULE
  END MODULE
@end smallexample
@end smallexample
 
 
Here, @code{_MyProject_flags} is the case-sensitive name of the variable
Here, @code{_MyProject_flags} is the case-sensitive name of the variable
as seen from C programs while @code{global_flag} is the case-insensitive
as seen from C programs while @code{global_flag} is the case-insensitive
name as seen from Fortran. If no binding name is specified, as for
name as seen from Fortran. If no binding name is specified, as for
@var{tp}, the C binding name is the (lowercase) Fortran binding name.
@var{tp}, the C binding name is the (lowercase) Fortran binding name.
If a binding name is specified, only a single variable may be after the
If a binding name is specified, only a single variable may be after the
double colon. Note of warning: You cannot use a global variable to
double colon. Note of warning: You cannot use a global variable to
access @var{errno} of the C library as the C standard allows it to be
access @var{errno} of the C library as the C standard allows it to be
a macro. Use the @code{IERRNO} intrinsic (GNU extension) instead.
a macro. Use the @code{IERRNO} intrinsic (GNU extension) instead.
 
 
@node Interoperable Subroutines and Functions
@node Interoperable Subroutines and Functions
@subsection Interoperable Subroutines and Functions
@subsection Interoperable Subroutines and Functions
 
 
Subroutines and functions have to have the @code{BIND(C)} attribute to
Subroutines and functions have to have the @code{BIND(C)} attribute to
be compatible with C. The dummy argument declaration is relatively
be compatible with C. The dummy argument declaration is relatively
straightforward. However, one needs to be careful because C uses
straightforward. However, one needs to be careful because C uses
call-by-value by default while Fortran behaves usually similar to
call-by-value by default while Fortran behaves usually similar to
call-by-reference. Furthermore, strings and pointers are handled
call-by-reference. Furthermore, strings and pointers are handled
differently. Note that only explicit size and assumed-size arrays are
differently. Note that only explicit size and assumed-size arrays are
supported but not assumed-shape or allocatable arrays.
supported but not assumed-shape or allocatable arrays.
 
 
To pass a variable by value, use the @code{VALUE} attribute.
To pass a variable by value, use the @code{VALUE} attribute.
Thus the following C prototype
Thus the following C prototype
 
 
@smallexample
@smallexample
@code{int func(int i, int *j)}
@code{int func(int i, int *j)}
@end smallexample
@end smallexample
 
 
matches the Fortran declaration
matches the Fortran declaration
 
 
@smallexample
@smallexample
  integer(c_int) function func(i,j)
  integer(c_int) function func(i,j)
    use iso_c_binding, only: c_int
    use iso_c_binding, only: c_int
    integer(c_int), VALUE :: i
    integer(c_int), VALUE :: i
    integer(c_int) :: j
    integer(c_int) :: j
@end smallexample
@end smallexample
 
 
Note that pointer arguments also frequently need the @code{VALUE} attribute.
Note that pointer arguments also frequently need the @code{VALUE} attribute.
 
 
Strings are handled quite differently in C and Fortran. In C a string
Strings are handled quite differently in C and Fortran. In C a string
is a @code{NUL}-terminated array of characters while in Fortran each string
is a @code{NUL}-terminated array of characters while in Fortran each string
has a length associated with it and is thus not terminated (by e.g.
has a length associated with it and is thus not terminated (by e.g.
@code{NUL}). For example, if one wants to use the following C function,
@code{NUL}). For example, if one wants to use the following C function,
 
 
@smallexample
@smallexample
  #include <stdio.h>
  #include <stdio.h>
  void print_C(char *string) /* equivalent: char string[]  */
  void print_C(char *string) /* equivalent: char string[]  */
  @{
  @{
     printf("%s\n", string);
     printf("%s\n", string);
  @}
  @}
@end smallexample
@end smallexample
 
 
to print ``Hello World'' from Fortran, one can call it using
to print ``Hello World'' from Fortran, one can call it using
 
 
@smallexample
@smallexample
  use iso_c_binding, only: C_CHAR, C_NULL_CHAR
  use iso_c_binding, only: C_CHAR, C_NULL_CHAR
  interface
  interface
    subroutine print_c(string) bind(C, name="print_C")
    subroutine print_c(string) bind(C, name="print_C")
      use iso_c_binding, only: c_char
      use iso_c_binding, only: c_char
      character(kind=c_char) :: string(*)
      character(kind=c_char) :: string(*)
    end subroutine print_c
    end subroutine print_c
  end interface
  end interface
  call print_c(C_CHAR_"Hello World"//C_NULL_CHAR)
  call print_c(C_CHAR_"Hello World"//C_NULL_CHAR)
@end smallexample
@end smallexample
 
 
As the example shows, one needs to ensure that the
As the example shows, one needs to ensure that the
string is @code{NUL} terminated. Additionally, the dummy argument
string is @code{NUL} terminated. Additionally, the dummy argument
@var{string} of @code{print_C} is a length-one assumed-size
@var{string} of @code{print_C} is a length-one assumed-size
array; using @code{character(len=*)} is not allowed. The example
array; using @code{character(len=*)} is not allowed. The example
above uses @code{c_char_"Hello World"} to ensure the string
above uses @code{c_char_"Hello World"} to ensure the string
literal has the right type; typically the default character
literal has the right type; typically the default character
kind and @code{c_char} are the same and thus @code{"Hello World"}
kind and @code{c_char} are the same and thus @code{"Hello World"}
is equivalent. However, the standard does not guarantee this.
is equivalent. However, the standard does not guarantee this.
 
 
The use of pointers is now illustrated using the C library
The use of pointers is now illustrated using the C library
function @code{strncpy}, whose prototype is
function @code{strncpy}, whose prototype is
 
 
@smallexample
@smallexample
  char *strncpy(char *restrict s1, const char *restrict s2, size_t n);
  char *strncpy(char *restrict s1, const char *restrict s2, size_t n);
@end smallexample
@end smallexample
 
 
The function @code{strncpy} copies at most @var{n} characters from
The function @code{strncpy} copies at most @var{n} characters from
string @var{s2} to @var{s1} and returns @var{s1}. In the following
string @var{s2} to @var{s1} and returns @var{s1}. In the following
example, we ignore the return value:
example, we ignore the return value:
 
 
@smallexample
@smallexample
  use iso_c_binding
  use iso_c_binding
  implicit none
  implicit none
  character(len=30) :: str,str2
  character(len=30) :: str,str2
  interface
  interface
    ! Ignore the return value of strncpy -> subroutine
    ! Ignore the return value of strncpy -> subroutine
    ! "restrict" is always assumed if we do not pass a pointer
    ! "restrict" is always assumed if we do not pass a pointer
    subroutine strncpy(dest, src, n) bind(C)
    subroutine strncpy(dest, src, n) bind(C)
      import
      import
      character(kind=c_char),  intent(out) :: dest(*)
      character(kind=c_char),  intent(out) :: dest(*)
      character(kind=c_char),  intent(in)  :: src(*)
      character(kind=c_char),  intent(in)  :: src(*)
      integer(c_size_t), value, intent(in) :: n
      integer(c_size_t), value, intent(in) :: n
    end subroutine strncpy
    end subroutine strncpy
  end interface
  end interface
  str = repeat('X',30) ! Initialize whole string with 'X'
  str = repeat('X',30) ! Initialize whole string with 'X'
  call strncpy(str, c_char_"Hello World"//C_NULL_CHAR, &
  call strncpy(str, c_char_"Hello World"//C_NULL_CHAR, &
               len(c_char_"Hello World",kind=c_size_t))
               len(c_char_"Hello World",kind=c_size_t))
  print '(a)', str ! prints: "Hello WorldXXXXXXXXXXXXXXXXXXX"
  print '(a)', str ! prints: "Hello WorldXXXXXXXXXXXXXXXXXXX"
  end
  end
@end smallexample
@end smallexample
 
 
C pointers are represented in Fortran via the special derived type
C pointers are represented in Fortran via the special derived type
@code{type(c_ptr)}, with private components. Thus one needs to
@code{type(c_ptr)}, with private components. Thus one needs to
use intrinsic conversion procedures to convert from or to C pointers.
use intrinsic conversion procedures to convert from or to C pointers.
For example,
For example,
 
 
@smallexample
@smallexample
  use iso_c_binding
  use iso_c_binding
  type(c_ptr) :: cptr1, cptr2
  type(c_ptr) :: cptr1, cptr2
  integer, target :: array(7), scalar
  integer, target :: array(7), scalar
  integer, pointer :: pa(:), ps
  integer, pointer :: pa(:), ps
  cptr1 = c_loc(array(1)) ! The programmer needs to ensure that the
  cptr1 = c_loc(array(1)) ! The programmer needs to ensure that the
                          ! array is contiguous if required by the C
                          ! array is contiguous if required by the C
                          ! procedure
                          ! procedure
  cptr2 = c_loc(scalar)
  cptr2 = c_loc(scalar)
  call c_f_pointer(cptr2, ps)
  call c_f_pointer(cptr2, ps)
  call c_f_pointer(cptr2, pa, shape=[7])
  call c_f_pointer(cptr2, pa, shape=[7])
@end smallexample
@end smallexample
 
 
When converting C to Fortran arrays, the one-dimensional @code{SHAPE} argument
When converting C to Fortran arrays, the one-dimensional @code{SHAPE} argument
has to be passed. Note: A pointer argument @code{void *} matches
has to be passed. Note: A pointer argument @code{void *} matches
@code{TYPE(C_PTR), VALUE} while @code{TYPE(C_PTR)} matches @code{void **}.
@code{TYPE(C_PTR), VALUE} while @code{TYPE(C_PTR)} matches @code{void **}.
 
 
Procedure pointers are handled analogously to pointers; the C type is
Procedure pointers are handled analogously to pointers; the C type is
@code{TYPE(C_FUNPTR)} and the intrinsic conversion procedures are
@code{TYPE(C_FUNPTR)} and the intrinsic conversion procedures are
@code{C_F_PROC_POINTER} and @code{C_FUNLOC}.
@code{C_F_PROC_POINTER} and @code{C_FUNLOC}.
 
 
The intrinsic procedures are described in @ref{Intrinsic Procedures}.
The intrinsic procedures are described in @ref{Intrinsic Procedures}.
 
 
@node Further Interoperability of Fortran with C
@node Further Interoperability of Fortran with C
@subsection Further Interoperability of Fortran with C
@subsection Further Interoperability of Fortran with C
 
 
Assumed-shape and allocatable arrays are passed using an array descriptor
Assumed-shape and allocatable arrays are passed using an array descriptor
(dope vector). The internal structure of the array descriptor used
(dope vector). The internal structure of the array descriptor used
by GNU Fortran is not yet documented and will change. There will also be
by GNU Fortran is not yet documented and will change. There will also be
a Technical Report (TR 29113) which standardizes an interoperable
a Technical Report (TR 29113) which standardizes an interoperable
array descriptor. Until then, you can use the Chasm Language
array descriptor. Until then, you can use the Chasm Language
Interoperability Tools, @url{http://chasm-interop.sourceforge.net/},
Interoperability Tools, @url{http://chasm-interop.sourceforge.net/},
which provide an interface to GNU Fortran's array descriptor.
which provide an interface to GNU Fortran's array descriptor.
 
 
The technical report 29113 will presumably also include support for
The technical report 29113 will presumably also include support for
C-interoperable @code{OPTIONAL} and for assumed-rank and assumed-type
C-interoperable @code{OPTIONAL} and for assumed-rank and assumed-type
dummy arguments. However, the TR has neither been approved nor implemented
dummy arguments. However, the TR has neither been approved nor implemented
in GNU Fortran; therefore, these features are not yet available.
in GNU Fortran; therefore, these features are not yet available.
 
 
 
 
 
 
@node GNU Fortran Compiler Directives
@node GNU Fortran Compiler Directives
@section GNU Fortran Compiler Directives
@section GNU Fortran Compiler Directives
 
 
The Fortran standard standard describes how a conforming program shall
The Fortran standard standard describes how a conforming program shall
behave; however, the exact implementation is not standardized. In order
behave; however, the exact implementation is not standardized. In order
to allow the user to choose specific implementation details, compiler
to allow the user to choose specific implementation details, compiler
directives can be used to set attributes of variables and procedures
directives can be used to set attributes of variables and procedures
which are not part of the standard. Whether a given attribute is
which are not part of the standard. Whether a given attribute is
supported and its exact effects depend on both the operating system and
supported and its exact effects depend on both the operating system and
on the processor; see
on the processor; see
@ref{Top,,C Extensions,gcc,Using the GNU Compiler Collection (GCC)}
@ref{Top,,C Extensions,gcc,Using the GNU Compiler Collection (GCC)}
for details.
for details.
 
 
For procedures and procedure pointers, the following attributes can
For procedures and procedure pointers, the following attributes can
be used to change the calling convention:
be used to change the calling convention:
 
 
@itemize
@itemize
@item @code{CDECL} -- standard C calling convention
@item @code{CDECL} -- standard C calling convention
@item @code{STDCALL} -- convention where the called procedure pops the stack
@item @code{STDCALL} -- convention where the called procedure pops the stack
@item @code{FASTCALL} -- part of the arguments are passed via registers
@item @code{FASTCALL} -- part of the arguments are passed via registers
instead using the stack
instead using the stack
@end itemize
@end itemize
 
 
Besides changing the calling convention, the attributes also influence
Besides changing the calling convention, the attributes also influence
the decoration of the symbol name, e.g., by a leading underscore or by
the decoration of the symbol name, e.g., by a leading underscore or by
a trailing at-sign followed by the number of bytes on the stack. When
a trailing at-sign followed by the number of bytes on the stack. When
assigning a procedure to a procedure pointer, both should use the same
assigning a procedure to a procedure pointer, both should use the same
calling convention.
calling convention.
 
 
On some systems, procedures and global variables (module variables and
On some systems, procedures and global variables (module variables and
@code{COMMON} blocks) need special handling to be accessible when they
@code{COMMON} blocks) need special handling to be accessible when they
are in a shared library. The following attributes are available:
are in a shared library. The following attributes are available:
 
 
@itemize
@itemize
@item @code{DLLEXPORT} -- provide a global pointer to a pointer in the DLL
@item @code{DLLEXPORT} -- provide a global pointer to a pointer in the DLL
@item @code{DLLIMPORT} -- reference the function or variable using a global pointer
@item @code{DLLIMPORT} -- reference the function or variable using a global pointer
@end itemize
@end itemize
 
 
The attributes are specified using the syntax
The attributes are specified using the syntax
 
 
@code{!GCC$ ATTRIBUTES} @var{attribute-list} @code{::} @var{variable-list}
@code{!GCC$ ATTRIBUTES} @var{attribute-list} @code{::} @var{variable-list}
 
 
where in free-form source code only whitespace is allowed before @code{!GCC$}
where in free-form source code only whitespace is allowed before @code{!GCC$}
and in fixed-form source code @code{!GCC$}, @code{cGCC$} or @code{*GCC$} shall
and in fixed-form source code @code{!GCC$}, @code{cGCC$} or @code{*GCC$} shall
start in the first column.
start in the first column.
 
 
For procedures, the compiler directives shall be placed into the body
For procedures, the compiler directives shall be placed into the body
of the procedure; for variables and procedure pointers, they shall be in
of the procedure; for variables and procedure pointers, they shall be in
the same declaration part as the variable or procedure pointer.
the same declaration part as the variable or procedure pointer.
 
 
 
 
 
 
@node Non-Fortran Main Program
@node Non-Fortran Main Program
@section Non-Fortran Main Program
@section Non-Fortran Main Program
 
 
@menu
@menu
* _gfortran_set_args:: Save command-line arguments
* _gfortran_set_args:: Save command-line arguments
* _gfortran_set_options:: Set library option flags
* _gfortran_set_options:: Set library option flags
* _gfortran_set_convert:: Set endian conversion
* _gfortran_set_convert:: Set endian conversion
* _gfortran_set_record_marker:: Set length of record markers
* _gfortran_set_record_marker:: Set length of record markers
* _gfortran_set_max_subrecord_length:: Set subrecord length
* _gfortran_set_max_subrecord_length:: Set subrecord length
* _gfortran_set_fpe:: Set when a Floating Point Exception should be raised
* _gfortran_set_fpe:: Set when a Floating Point Exception should be raised
@end menu
@end menu
 
 
Even if you are doing mixed-language programming, it is very
Even if you are doing mixed-language programming, it is very
likely that you do not need to know or use the information in this
likely that you do not need to know or use the information in this
section. Since it is about the internal structure of GNU Fortran,
section. Since it is about the internal structure of GNU Fortran,
it may also change in GCC minor releases.
it may also change in GCC minor releases.
 
 
When you compile a @code{PROGRAM} with GNU Fortran, a function
When you compile a @code{PROGRAM} with GNU Fortran, a function
with the name @code{main} (in the symbol table of the object file)
with the name @code{main} (in the symbol table of the object file)
is generated, which initializes the libgfortran library and then
is generated, which initializes the libgfortran library and then
calls the actual program which uses the name @code{MAIN__}, for
calls the actual program which uses the name @code{MAIN__}, for
historic reasons. If you link GNU Fortran compiled procedures
historic reasons. If you link GNU Fortran compiled procedures
to, e.g., a C or C++ program or to a Fortran program compiled by
to, e.g., a C or C++ program or to a Fortran program compiled by
a different compiler, the libgfortran library is not initialized
a different compiler, the libgfortran library is not initialized
and thus a few intrinsic procedures do not work properly, e.g.
and thus a few intrinsic procedures do not work properly, e.g.
those for obtaining the command-line arguments.
those for obtaining the command-line arguments.
 
 
Therefore, if your @code{PROGRAM} is not compiled with
Therefore, if your @code{PROGRAM} is not compiled with
GNU Fortran and the GNU Fortran compiled procedures require
GNU Fortran and the GNU Fortran compiled procedures require
intrinsics relying on the library initialization, you need to
intrinsics relying on the library initialization, you need to
initialize the library yourself. Using the default options,
initialize the library yourself. Using the default options,
gfortran calls @code{_gfortran_set_args} and
gfortran calls @code{_gfortran_set_args} and
@code{_gfortran_set_options}. The initialization of the former
@code{_gfortran_set_options}. The initialization of the former
is needed if the called procedures access the command line
is needed if the called procedures access the command line
(and for backtracing); the latter sets some flags based on the
(and for backtracing); the latter sets some flags based on the
standard chosen or to enable backtracing. In typical programs,
standard chosen or to enable backtracing. In typical programs,
it is not necessary to call any initialization function.
it is not necessary to call any initialization function.
 
 
If your @code{PROGRAM} is compiled with GNU Fortran, you shall
If your @code{PROGRAM} is compiled with GNU Fortran, you shall
not call any of the following functions. The libgfortran
not call any of the following functions. The libgfortran
initialization functions are shown in C syntax but using C
initialization functions are shown in C syntax but using C
bindings they are also accessible from Fortran.
bindings they are also accessible from Fortran.
 
 
 
 
@node _gfortran_set_args
@node _gfortran_set_args
@subsection @code{_gfortran_set_args} --- Save command-line arguments
@subsection @code{_gfortran_set_args} --- Save command-line arguments
@fnindex _gfortran_set_args
@fnindex _gfortran_set_args
@cindex libgfortran initialization, set_args
@cindex libgfortran initialization, set_args
 
 
@table @asis
@table @asis
@item @emph{Description}:
@item @emph{Description}:
@code{_gfortran_set_args} saves the command-line arguments; this
@code{_gfortran_set_args} saves the command-line arguments; this
initialization is required if any of the command-line intrinsics
initialization is required if any of the command-line intrinsics
is called. Additionally, it shall be called if backtracing is
is called. Additionally, it shall be called if backtracing is
enabled (see @code{_gfortran_set_options}).
enabled (see @code{_gfortran_set_options}).
 
 
@item @emph{Syntax}:
@item @emph{Syntax}:
@code{void _gfortran_set_args (int argc, char *argv[])}
@code{void _gfortran_set_args (int argc, char *argv[])}
 
 
@item @emph{Arguments}:
@item @emph{Arguments}:
@multitable @columnfractions .15 .70
@multitable @columnfractions .15 .70
@item @var{argc} @tab number of command line argument strings
@item @var{argc} @tab number of command line argument strings
@item @var{argv} @tab the command-line argument strings; argv[0]
@item @var{argv} @tab the command-line argument strings; argv[0]
is the pathname of the executable itself.
is the pathname of the executable itself.
@end multitable
@end multitable
 
 
@item @emph{Example}:
@item @emph{Example}:
@smallexample
@smallexample
int main (int argc, char *argv[])
int main (int argc, char *argv[])
@{
@{
  /* Initialize libgfortran.  */
  /* Initialize libgfortran.  */
  _gfortran_set_args (argc, argv);
  _gfortran_set_args (argc, argv);
  return 0;
  return 0;
@}
@}
@end smallexample
@end smallexample
@end table
@end table
 
 
 
 
@node _gfortran_set_options
@node _gfortran_set_options
@subsection @code{_gfortran_set_options} --- Set library option flags
@subsection @code{_gfortran_set_options} --- Set library option flags
@fnindex _gfortran_set_options
@fnindex _gfortran_set_options
@cindex libgfortran initialization, set_options
@cindex libgfortran initialization, set_options
 
 
@table @asis
@table @asis
@item @emph{Description}:
@item @emph{Description}:
@code{_gfortran_set_options} sets several flags related to the Fortran
@code{_gfortran_set_options} sets several flags related to the Fortran
standard to be used, whether backtracing or core dumps should be enabled
standard to be used, whether backtracing or core dumps should be enabled
and whether range checks should be performed. The syntax allows for
and whether range checks should be performed. The syntax allows for
upward compatibility since the number of passed flags is specified; for
upward compatibility since the number of passed flags is specified; for
non-passed flags, the default value is used. See also
non-passed flags, the default value is used. See also
@pxref{Code Gen Options}. Please note that not all flags are actually
@pxref{Code Gen Options}. Please note that not all flags are actually
used.
used.
 
 
@item @emph{Syntax}:
@item @emph{Syntax}:
@code{void _gfortran_set_options (int num, int options[])}
@code{void _gfortran_set_options (int num, int options[])}
 
 
@item @emph{Arguments}:
@item @emph{Arguments}:
@multitable @columnfractions .15 .70
@multitable @columnfractions .15 .70
@item @var{num} @tab number of options passed
@item @var{num} @tab number of options passed
@item @var{argv} @tab The list of flag values
@item @var{argv} @tab The list of flag values
@end multitable
@end multitable
 
 
@item @emph{option flag list}:
@item @emph{option flag list}:
@multitable @columnfractions .15 .70
@multitable @columnfractions .15 .70
@item @var{option}[0] @tab Allowed standard; can give run-time errors
@item @var{option}[0] @tab Allowed standard; can give run-time errors
if e.g. an input-output edit descriptor is invalid in a given standard.
if e.g. an input-output edit descriptor is invalid in a given standard.
Possible values are (bitwise or-ed) @code{GFC_STD_F77} (1),
Possible values are (bitwise or-ed) @code{GFC_STD_F77} (1),
@code{GFC_STD_F95_OBS} (2), @code{GFC_STD_F95_DEL} (4), @code{GFC_STD_F95}
@code{GFC_STD_F95_OBS} (2), @code{GFC_STD_F95_DEL} (4), @code{GFC_STD_F95}
(8), @code{GFC_STD_F2003} (16), @code{GFC_STD_GNU} (32),
(8), @code{GFC_STD_F2003} (16), @code{GFC_STD_GNU} (32),
@code{GFC_STD_LEGACY} (64), and @code{GFC_STD_F2008} (128).
@code{GFC_STD_LEGACY} (64), and @code{GFC_STD_F2008} (128).
Default: @code{GFC_STD_F95_OBS | GFC_STD_F95_DEL | GFC_STD_F2003
Default: @code{GFC_STD_F95_OBS | GFC_STD_F95_DEL | GFC_STD_F2003
| GFC_STD_F2008 | GFC_STD_F95 | GFC_STD_F77 | GFC_STD_GNU | GFC_STD_LEGACY}.
| GFC_STD_F2008 | GFC_STD_F95 | GFC_STD_F77 | GFC_STD_GNU | GFC_STD_LEGACY}.
@item @var{option}[1] @tab Standard-warning flag; prints a warning to
@item @var{option}[1] @tab Standard-warning flag; prints a warning to
standard error. Default: @code{GFC_STD_F95_DEL | GFC_STD_LEGACY}.
standard error. Default: @code{GFC_STD_F95_DEL | GFC_STD_LEGACY}.
@item @var{option}[2] @tab If non zero, enable pedantic checking.
@item @var{option}[2] @tab If non zero, enable pedantic checking.
Default: off.
Default: off.
@item @var{option}[3] @tab If non zero, enable core dumps on run-time
@item @var{option}[3] @tab If non zero, enable core dumps on run-time
errors. Default: off.
errors. Default: off.
@item @var{option}[4] @tab If non zero, enable backtracing on run-time
@item @var{option}[4] @tab If non zero, enable backtracing on run-time
errors. Default: off.
errors. Default: off.
Note: Installs a signal handler and requires command-line
Note: Installs a signal handler and requires command-line
initialization using @code{_gfortran_set_args}.
initialization using @code{_gfortran_set_args}.
@item @var{option}[5] @tab If non zero, supports signed zeros.
@item @var{option}[5] @tab If non zero, supports signed zeros.
Default: enabled.
Default: enabled.
@item @var{option}[6] @tab Enables run-time checking. Possible values
@item @var{option}[6] @tab Enables run-time checking. Possible values
are (bitwise or-ed): GFC_RTCHECK_BOUNDS (1), GFC_RTCHECK_ARRAY_TEMPS (2),
are (bitwise or-ed): GFC_RTCHECK_BOUNDS (1), GFC_RTCHECK_ARRAY_TEMPS (2),
GFC_RTCHECK_RECURSION (4), GFC_RTCHECK_DO (16), GFC_RTCHECK_POINTER (32).
GFC_RTCHECK_RECURSION (4), GFC_RTCHECK_DO (16), GFC_RTCHECK_POINTER (32).
Default: disabled.
Default: disabled.
@item @var{option}[7] @tab If non zero, range checking is enabled.
@item @var{option}[7] @tab If non zero, range checking is enabled.
Default: enabled. See -frange-check (@pxref{Code Gen Options}).
Default: enabled. See -frange-check (@pxref{Code Gen Options}).
@end multitable
@end multitable
 
 
@item @emph{Example}:
@item @emph{Example}:
@smallexample
@smallexample
  /* Use gfortran 4.5 default options.  */
  /* Use gfortran 4.5 default options.  */
  static int options[] = @{68, 255, 0, 0, 0, 1, 0, 1@};
  static int options[] = @{68, 255, 0, 0, 0, 1, 0, 1@};
  _gfortran_set_options (8, &options);
  _gfortran_set_options (8, &options);
@end smallexample
@end smallexample
@end table
@end table
 
 
 
 
@node _gfortran_set_convert
@node _gfortran_set_convert
@subsection @code{_gfortran_set_convert} --- Set endian conversion
@subsection @code{_gfortran_set_convert} --- Set endian conversion
@fnindex _gfortran_set_convert
@fnindex _gfortran_set_convert
@cindex libgfortran initialization, set_convert
@cindex libgfortran initialization, set_convert
 
 
@table @asis
@table @asis
@item @emph{Description}:
@item @emph{Description}:
@code{_gfortran_set_convert} set the representation of data for
@code{_gfortran_set_convert} set the representation of data for
unformatted files.
unformatted files.
 
 
@item @emph{Syntax}:
@item @emph{Syntax}:
@code{void _gfortran_set_convert (int conv)}
@code{void _gfortran_set_convert (int conv)}
 
 
@item @emph{Arguments}:
@item @emph{Arguments}:
@multitable @columnfractions .15 .70
@multitable @columnfractions .15 .70
@item @var{conv} @tab Endian conversion, possible values:
@item @var{conv} @tab Endian conversion, possible values:
GFC_CONVERT_NATIVE (0, default), GFC_CONVERT_SWAP (1),
GFC_CONVERT_NATIVE (0, default), GFC_CONVERT_SWAP (1),
GFC_CONVERT_BIG (2), GFC_CONVERT_LITTLE (3).
GFC_CONVERT_BIG (2), GFC_CONVERT_LITTLE (3).
@end multitable
@end multitable
 
 
@item @emph{Example}:
@item @emph{Example}:
@smallexample
@smallexample
int main (int argc, char *argv[])
int main (int argc, char *argv[])
@{
@{
  /* Initialize libgfortran.  */
  /* Initialize libgfortran.  */
  _gfortran_set_args (argc, argv);
  _gfortran_set_args (argc, argv);
  _gfortran_set_convert (1);
  _gfortran_set_convert (1);
  return 0;
  return 0;
@}
@}
@end smallexample
@end smallexample
@end table
@end table
 
 
 
 
@node _gfortran_set_record_marker
@node _gfortran_set_record_marker
@subsection @code{_gfortran_set_record_marker} --- Set length of record markers
@subsection @code{_gfortran_set_record_marker} --- Set length of record markers
@fnindex _gfortran_set_record_marker
@fnindex _gfortran_set_record_marker
@cindex libgfortran initialization, set_record_marker
@cindex libgfortran initialization, set_record_marker
 
 
@table @asis
@table @asis
@item @emph{Description}:
@item @emph{Description}:
@code{_gfortran_set_record_marker} sets the length of record markers
@code{_gfortran_set_record_marker} sets the length of record markers
for unformatted files.
for unformatted files.
 
 
@item @emph{Syntax}:
@item @emph{Syntax}:
@code{void _gfortran_set_record_marker (int val)}
@code{void _gfortran_set_record_marker (int val)}
 
 
@item @emph{Arguments}:
@item @emph{Arguments}:
@multitable @columnfractions .15 .70
@multitable @columnfractions .15 .70
@item @var{val} @tab Length of the record marker; valid values
@item @var{val} @tab Length of the record marker; valid values
are 4 and 8. Default is 4.
are 4 and 8. Default is 4.
@end multitable
@end multitable
 
 
@item @emph{Example}:
@item @emph{Example}:
@smallexample
@smallexample
int main (int argc, char *argv[])
int main (int argc, char *argv[])
@{
@{
  /* Initialize libgfortran.  */
  /* Initialize libgfortran.  */
  _gfortran_set_args (argc, argv);
  _gfortran_set_args (argc, argv);
  _gfortran_set_record_marker (8);
  _gfortran_set_record_marker (8);
  return 0;
  return 0;
@}
@}
@end smallexample
@end smallexample
@end table
@end table
 
 
 
 
@node _gfortran_set_fpe
@node _gfortran_set_fpe
@subsection @code{_gfortran_set_fpe} --- Set when a Floating Point Exception should be raised
@subsection @code{_gfortran_set_fpe} --- Set when a Floating Point Exception should be raised
@fnindex _gfortran_set_fpe
@fnindex _gfortran_set_fpe
@cindex libgfortran initialization, set_fpe
@cindex libgfortran initialization, set_fpe
 
 
@table @asis
@table @asis
@item @emph{Description}:
@item @emph{Description}:
@code{_gfortran_set_fpe} sets the IEEE exceptions for which a
@code{_gfortran_set_fpe} sets the IEEE exceptions for which a
Floating Point Exception (FPE) should be raised. On most systems,
Floating Point Exception (FPE) should be raised. On most systems,
this will result in a SIGFPE signal being sent and the program
this will result in a SIGFPE signal being sent and the program
being interrupted.
being interrupted.
 
 
@item @emph{Syntax}:
@item @emph{Syntax}:
@code{void _gfortran_set_fpe (int val)}
@code{void _gfortran_set_fpe (int val)}
 
 
@item @emph{Arguments}:
@item @emph{Arguments}:
@multitable @columnfractions .15 .70
@multitable @columnfractions .15 .70
@item @var{option}[0] @tab IEEE exceptions. Possible values are
@item @var{option}[0] @tab IEEE exceptions. Possible values are
(bitwise or-ed) zero (0, default) no trapping,
(bitwise or-ed) zero (0, default) no trapping,
@code{GFC_FPE_INVALID} (1), @code{GFC_FPE_DENORMAL} (2),
@code{GFC_FPE_INVALID} (1), @code{GFC_FPE_DENORMAL} (2),
@code{GFC_FPE_ZERO} (4), @code{GFC_FPE_OVERFLOW} (8),
@code{GFC_FPE_ZERO} (4), @code{GFC_FPE_OVERFLOW} (8),
@code{GFC_FPE_UNDERFLOW} (16), and @code{GFC_FPE_PRECISION} (32).
@code{GFC_FPE_UNDERFLOW} (16), and @code{GFC_FPE_PRECISION} (32).
@end multitable
@end multitable
 
 
@item @emph{Example}:
@item @emph{Example}:
@smallexample
@smallexample
int main (int argc, char *argv[])
int main (int argc, char *argv[])
@{
@{
  /* Initialize libgfortran.  */
  /* Initialize libgfortran.  */
  _gfortran_set_args (argc, argv);
  _gfortran_set_args (argc, argv);
  /* FPE for invalid operations such as SQRT(-1.0).  */
  /* FPE for invalid operations such as SQRT(-1.0).  */
  _gfortran_set_fpe (1);
  _gfortran_set_fpe (1);
  return 0;
  return 0;
@}
@}
@end smallexample
@end smallexample
@end table
@end table
 
 
 
 
@node _gfortran_set_max_subrecord_length
@node _gfortran_set_max_subrecord_length
@subsection @code{_gfortran_set_max_subrecord_length} --- Set subrecord length
@subsection @code{_gfortran_set_max_subrecord_length} --- Set subrecord length
@fnindex _gfortran_set_max_subrecord_length
@fnindex _gfortran_set_max_subrecord_length
@cindex libgfortran initialization, set_max_subrecord_length
@cindex libgfortran initialization, set_max_subrecord_length
 
 
@table @asis
@table @asis
@item @emph{Description}:
@item @emph{Description}:
@code{_gfortran_set_max_subrecord_length} set the maximum length
@code{_gfortran_set_max_subrecord_length} set the maximum length
for a subrecord. This option only makes sense for testing and
for a subrecord. This option only makes sense for testing and
debugging of unformatted I/O.
debugging of unformatted I/O.
 
 
@item @emph{Syntax}:
@item @emph{Syntax}:
@code{void _gfortran_set_max_subrecord_length (int val)}
@code{void _gfortran_set_max_subrecord_length (int val)}
 
 
@item @emph{Arguments}:
@item @emph{Arguments}:
@multitable @columnfractions .15 .70
@multitable @columnfractions .15 .70
@item @var{val} @tab the maximum length for a subrecord;
@item @var{val} @tab the maximum length for a subrecord;
the maximum permitted value is 2147483639, which is also
the maximum permitted value is 2147483639, which is also
the default.
the default.
@end multitable
@end multitable
 
 
@item @emph{Example}:
@item @emph{Example}:
@smallexample
@smallexample
int main (int argc, char *argv[])
int main (int argc, char *argv[])
@{
@{
  /* Initialize libgfortran.  */
  /* Initialize libgfortran.  */
  _gfortran_set_args (argc, argv);
  _gfortran_set_args (argc, argv);
  _gfortran_set_max_subrecord_length (8);
  _gfortran_set_max_subrecord_length (8);
  return 0;
  return 0;
@}
@}
@end smallexample
@end smallexample
@end table
@end table
 
 
 
 
 
 
@c Intrinsic Procedures
@c Intrinsic Procedures
@c ---------------------------------------------------------------------
@c ---------------------------------------------------------------------
 
 
@include intrinsic.texi
@include intrinsic.texi
 
 
 
 
@tex
@tex
\blankpart
\blankpart
@end tex
@end tex
 
 
@c ---------------------------------------------------------------------
@c ---------------------------------------------------------------------
@c Contributing
@c Contributing
@c ---------------------------------------------------------------------
@c ---------------------------------------------------------------------
 
 
@node Contributing
@node Contributing
@unnumbered Contributing
@unnumbered Contributing
@cindex Contributing
@cindex Contributing
 
 
Free software is only possible if people contribute to efforts
Free software is only possible if people contribute to efforts
to create it.
to create it.
We're always in need of more people helping out with ideas
We're always in need of more people helping out with ideas
and comments, writing documentation and contributing code.
and comments, writing documentation and contributing code.
 
 
If you want to contribute to GNU Fortran,
If you want to contribute to GNU Fortran,
have a look at the long lists of projects you can take on.
have a look at the long lists of projects you can take on.
Some of these projects are small,
Some of these projects are small,
some of them are large;
some of them are large;
some are completely orthogonal to the rest of what is
some are completely orthogonal to the rest of what is
happening on GNU Fortran,
happening on GNU Fortran,
but others are ``mainstream'' projects in need of enthusiastic hackers.
but others are ``mainstream'' projects in need of enthusiastic hackers.
All of these projects are important!
All of these projects are important!
We'll eventually get around to the things here,
We'll eventually get around to the things here,
but they are also things doable by someone who is willing and able.
but they are also things doable by someone who is willing and able.
 
 
@menu
@menu
* Contributors::
* Contributors::
* Projects::
* Projects::
* Proposed Extensions::
* Proposed Extensions::
@end menu
@end menu
 
 
 
 
@node Contributors
@node Contributors
@section Contributors to GNU Fortran
@section Contributors to GNU Fortran
@cindex Contributors
@cindex Contributors
@cindex Credits
@cindex Credits
@cindex Authors
@cindex Authors
 
 
Most of the parser was hand-crafted by @emph{Andy Vaught}, who is
Most of the parser was hand-crafted by @emph{Andy Vaught}, who is
also the initiator of the whole project.  Thanks Andy!
also the initiator of the whole project.  Thanks Andy!
Most of the interface with GCC was written by @emph{Paul Brook}.
Most of the interface with GCC was written by @emph{Paul Brook}.
 
 
The following individuals have contributed code and/or
The following individuals have contributed code and/or
ideas and significant help to the GNU Fortran project
ideas and significant help to the GNU Fortran project
(in alphabetical order):
(in alphabetical order):
 
 
@itemize @minus
@itemize @minus
@item Janne Blomqvist
@item Janne Blomqvist
@item Steven Bosscher
@item Steven Bosscher
@item Paul Brook
@item Paul Brook
@item Tobias Burnus
@item Tobias Burnus
@item Fran@,{c}ois-Xavier Coudert
@item Fran@,{c}ois-Xavier Coudert
@item Bud Davis
@item Bud Davis
@item Jerry DeLisle
@item Jerry DeLisle
@item Erik Edelmann
@item Erik Edelmann
@item Bernhard Fischer
@item Bernhard Fischer
@item Daniel Franke
@item Daniel Franke
@item Richard Guenther
@item Richard Guenther
@item Richard Henderson
@item Richard Henderson
@item Katherine Holcomb
@item Katherine Holcomb
@item Jakub Jelinek
@item Jakub Jelinek
@item Niels Kristian Bech Jensen
@item Niels Kristian Bech Jensen
@item Steven Johnson
@item Steven Johnson
@item Steven G. Kargl
@item Steven G. Kargl
@item Thomas Koenig
@item Thomas Koenig
@item Asher Langton
@item Asher Langton
@item H. J. Lu
@item H. J. Lu
@item Toon Moene
@item Toon Moene
@item Brooks Moses
@item Brooks Moses
@item Andrew Pinski
@item Andrew Pinski
@item Tim Prince
@item Tim Prince
@item Christopher D. Rickett
@item Christopher D. Rickett
@item Richard Sandiford
@item Richard Sandiford
@item Tobias Schl@"uter
@item Tobias Schl@"uter
@item Roger Sayle
@item Roger Sayle
@item Paul Thomas
@item Paul Thomas
@item Andy Vaught
@item Andy Vaught
@item Feng Wang
@item Feng Wang
@item Janus Weil
@item Janus Weil
@item Daniel Kraft
@item Daniel Kraft
@end itemize
@end itemize
 
 
The following people have contributed bug reports,
The following people have contributed bug reports,
smaller or larger patches,
smaller or larger patches,
and much needed feedback and encouragement for the
and much needed feedback and encouragement for the
GNU Fortran project:
GNU Fortran project:
 
 
@itemize @minus
@itemize @minus
@item Bill Clodius
@item Bill Clodius
@item Dominique d'Humi@`eres
@item Dominique d'Humi@`eres
@item Kate Hedstrom
@item Kate Hedstrom
@item Erik Schnetter
@item Erik Schnetter
@item Joost VandeVondele
@item Joost VandeVondele
@end itemize
@end itemize
 
 
Many other individuals have helped debug,
Many other individuals have helped debug,
test and improve the GNU Fortran compiler over the past few years,
test and improve the GNU Fortran compiler over the past few years,
and we welcome you to do the same!
and we welcome you to do the same!
If you already have done so,
If you already have done so,
and you would like to see your name listed in the
and you would like to see your name listed in the
list above, please contact us.
list above, please contact us.
 
 
 
 
@node Projects
@node Projects
@section Projects
@section Projects
 
 
@table @emph
@table @emph
 
 
@item Help build the test suite
@item Help build the test suite
Solicit more code for donation to the test suite: the more extensive the
Solicit more code for donation to the test suite: the more extensive the
testsuite, the smaller the risk of breaking things in the future! We can
testsuite, the smaller the risk of breaking things in the future! We can
keep code private on request.
keep code private on request.
 
 
@item Bug hunting/squishing
@item Bug hunting/squishing
Find bugs and write more test cases! Test cases are especially very
Find bugs and write more test cases! Test cases are especially very
welcome, because it allows us to concentrate on fixing bugs instead of
welcome, because it allows us to concentrate on fixing bugs instead of
isolating them. Going through the bugzilla database at
isolating them. Going through the bugzilla database at
@url{http://gcc.gnu.org/bugzilla/} to reduce testcases posted there and
@url{http://gcc.gnu.org/bugzilla/} to reduce testcases posted there and
add more information (for example, for which version does the testcase
add more information (for example, for which version does the testcase
work, for which versions does it fail?) is also very helpful.
work, for which versions does it fail?) is also very helpful.
 
 
@end table
@end table
 
 
 
 
@node Proposed Extensions
@node Proposed Extensions
@section Proposed Extensions
@section Proposed Extensions
 
 
Here's a list of proposed extensions for the GNU Fortran compiler, in no particular
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
order.  Most of these are necessary to be fully compatible with
existing Fortran compilers, but they are not part of the official
existing Fortran compilers, but they are not part of the official
J3 Fortran 95 standard.
J3 Fortran 95 standard.
 
 
@subsection Compiler extensions:
@subsection Compiler extensions:
@itemize @bullet
@itemize @bullet
@item
@item
User-specified alignment rules for structures.
User-specified alignment rules for structures.
 
 
@item
@item
Flag to generate @code{Makefile} info.
 
 
 
@item
 
Automatically extend single precision constants to double.
Automatically extend single precision constants to double.
 
 
@item
@item
Compile code that conserves memory by dynamically allocating common and
Compile code that conserves memory by dynamically allocating common and
module storage either on stack or heap.
module storage either on stack or heap.
 
 
@item
@item
Compile flag to generate code for array conformance checking (suggest -CC).
Compile flag to generate code for array conformance checking (suggest -CC).
 
 
@item
@item
User control of symbol names (underscores, etc).
User control of symbol names (underscores, etc).
 
 
@item
@item
Compile setting for maximum size of stack frame size before spilling
Compile setting for maximum size of stack frame size before spilling
parts to static or heap.
parts to static or heap.
 
 
@item
@item
Flag to force local variables into static space.
Flag to force local variables into static space.
 
 
@item
@item
Flag to force local variables onto stack.
Flag to force local variables onto stack.
@end itemize
@end itemize
 
 
 
 
@subsection Environment Options
@subsection Environment Options
@itemize @bullet
@itemize @bullet
@item
@item
Pluggable library modules for random numbers, linear algebra.
Pluggable library modules for random numbers, linear algebra.
LA should use BLAS calling conventions.
LA should use BLAS calling conventions.
 
 
@item
@item
Environment variables controlling actions on arithmetic exceptions like
Environment variables controlling actions on arithmetic exceptions like
overflow, underflow, precision loss---Generate NaN, abort, default.
overflow, underflow, precision loss---Generate NaN, abort, default.
action.
action.
 
 
@item
@item
Set precision for fp units that support it (i387).
Set precision for fp units that support it (i387).
 
 
@item
@item
Variable for setting fp rounding mode.
Variable for setting fp rounding mode.
 
 
@item
@item
Variable to fill uninitialized variables with a user-defined bit
Variable to fill uninitialized variables with a user-defined bit
pattern.
pattern.
 
 
@item
@item
Environment variable controlling filename that is opened for that unit
Environment variable controlling filename that is opened for that unit
number.
number.
 
 
@item
@item
Environment variable to clear/trash memory being freed.
Environment variable to clear/trash memory being freed.
 
 
@item
@item
Environment variable to control tracing of allocations and frees.
Environment variable to control tracing of allocations and frees.
 
 
@item
@item
Environment variable to display allocated memory at normal program end.
Environment variable to display allocated memory at normal program end.
 
 
@item
@item
Environment variable for filename for * IO-unit.
Environment variable for filename for * IO-unit.
 
 
@item
@item
Environment variable for temporary file directory.
Environment variable for temporary file directory.
 
 
@item
@item
Environment variable forcing standard output to be line buffered (unix).
Environment variable forcing standard output to be line buffered (unix).
 
 
@end itemize
@end itemize
 
 
 
 
@c ---------------------------------------------------------------------
@c ---------------------------------------------------------------------
@c GNU General Public License
@c GNU General Public License
@c ---------------------------------------------------------------------
@c ---------------------------------------------------------------------
 
 
@include gpl_v3.texi
@include gpl_v3.texi
 
 
 
 
 
 
@c ---------------------------------------------------------------------
@c ---------------------------------------------------------------------
@c GNU Free Documentation License
@c GNU Free Documentation License
@c ---------------------------------------------------------------------
@c ---------------------------------------------------------------------
 
 
@include fdl.texi
@include fdl.texi
 
 
 
 
 
 
@c ---------------------------------------------------------------------
@c ---------------------------------------------------------------------
@c Funding Free Software
@c Funding Free Software
@c ---------------------------------------------------------------------
@c ---------------------------------------------------------------------
 
 
@include funding.texi
@include funding.texi
 
 
@c ---------------------------------------------------------------------
@c ---------------------------------------------------------------------
@c Indices
@c Indices
@c ---------------------------------------------------------------------
@c ---------------------------------------------------------------------
 
 
@node Option Index
@node Option Index
@unnumbered Option Index
@unnumbered Option Index
@command{gfortran}'s command line options are indexed here without any
@command{gfortran}'s command line options are indexed here without any
initial @samp{-} or @samp{--}. Where an option has both positive and
initial @samp{-} or @samp{--}. Where an option has both positive and
negative forms (such as -foption and -fno-option), relevant entries in
negative forms (such as -foption and -fno-option), relevant entries in
the manual are indexed under the most appropriate form; it may sometimes
the manual are indexed under the most appropriate form; it may sometimes
be useful to look up both forms.
be useful to look up both forms.
@printindex op
@printindex op
 
 
@node Keyword Index
@node Keyword Index
@unnumbered Keyword Index
@unnumbered Keyword Index
@printindex cp
@printindex cp
 
 
@bye
@bye
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.