1\input texinfo  @c -*-texinfo-*-
2@c %**start of header
3@setfilename gfortran.info
4@set copyrights-gfortran 1999-2013
5
6@include gcc-common.texi
7
8@settitle The GNU Fortran Compiler
9
10@c Create a separate index for command line options
11@defcodeindex op
12@c Merge the standard indexes into a single one.
13@syncodeindex fn cp
14@syncodeindex vr cp
15@syncodeindex ky cp
16@syncodeindex pg cp
17@syncodeindex tp cp
18
19@c TODO: The following "Part" definitions are included here temporarily
20@c until they are incorporated into the official Texinfo distribution.
21@c They borrow heavily from Texinfo's \unnchapentry definitions.
22
23@tex
24\gdef\part#1#2{%
25  \pchapsepmacro
26  \gdef\thischapter{}
27  \begingroup
28    \vglue\titlepagetopglue
29    \titlefonts \rm
30    \leftline{Part #1:@* #2}
31    \vskip4pt \hrule height 4pt width \hsize \vskip4pt
32  \endgroup
33  \writetocentry{part}{#2}{#1}
34}
35\gdef\blankpart{%
36  \writetocentry{blankpart}{}{}
37}
38% Part TOC-entry definition for summary contents.
39\gdef\dosmallpartentry#1#2#3#4{%
40  \vskip .5\baselineskip plus.2\baselineskip
41  \begingroup
42    \let\rm=\bf \rm
43    \tocentry{Part #2: #1}{\doshortpageno\bgroup#4\egroup}
44  \endgroup
45}
46\gdef\dosmallblankpartentry#1#2#3#4{%
47  \vskip .5\baselineskip plus.2\baselineskip
48}
49% Part TOC-entry definition for regular contents.  This has to be
50% equated to an existing entry to not cause problems when the PDF
51% outline is created.
52\gdef\dopartentry#1#2#3#4{%
53  \unnchapentry{Part #2: #1}{}{#3}{#4}
54}
55\gdef\doblankpartentry#1#2#3#4{}
56@end tex
57
58@c %**end of header
59
60@c Use with @@smallbook.
61
62@c %** start of document
63
64@c Cause even numbered pages to be printed on the left hand side of
65@c the page and odd numbered pages to be printed on the right hand
66@c side of the page.  Using this, you can print on both sides of a
67@c sheet of paper and have the text on the same part of the sheet.
68
69@c The text on right hand pages is pushed towards the right hand
70@c margin and the text on left hand pages is pushed toward the left
71@c hand margin.
72@c (To provide the reverse effect, set bindingoffset to -0.75in.)
73
74@c @tex
75@c \global\bindingoffset=0.75in
76@c \global\normaloffset =0.75in
77@c @end tex
78
79@copying
80Copyright @copyright{} @value{copyrights-gfortran} Free Software Foundation, Inc.
81
82Permission is granted to copy, distribute and/or modify this document
83under the terms of the GNU Free Documentation License, Version 1.3 or
84any later version published by the Free Software Foundation; with the
85Invariant Sections being ``Funding Free Software'', the Front-Cover
86Texts being (a) (see below), and with the Back-Cover Texts being (b)
87(see below).  A copy of the license is included in the section entitled
88``GNU Free Documentation License''.
89
90(a) The FSF's Front-Cover Text is:
91
92     A GNU Manual
93
94(b) The FSF's Back-Cover Text is:
95
96     You have freedom to copy and modify this GNU Manual, like GNU
97     software.  Copies published by the Free Software Foundation raise
98     funds for GNU development.
99@end copying
100
101@ifinfo
102@dircategory Software development
103@direntry
104* gfortran: (gfortran).                  The GNU Fortran Compiler.
105@end direntry
106This file documents the use and the internals of
107the GNU Fortran compiler, (@command{gfortran}).
108
109Published by the Free Software Foundation
11051 Franklin Street, Fifth Floor
111Boston, MA 02110-1301 USA
112
113@insertcopying
114@end ifinfo
115
116
117@setchapternewpage odd
118@titlepage
119@title Using GNU Fortran
120@versionsubtitle
121@author The @t{gfortran} team
122@page
123@vskip 0pt plus 1filll
124Published by the Free Software Foundation@*
12551 Franklin Street, Fifth Floor@*
126Boston, MA 02110-1301, USA@*
127@c Last printed ??ber, 19??.@*
128@c Printed copies are available for $? each.@*
129@c ISBN ???
130@sp 1
131@insertcopying
132@end titlepage
133
134@c TODO: The following "Part" definitions are included here temporarily
135@c until they are incorporated into the official Texinfo distribution.
136
137@tex
138\global\let\partentry=\dosmallpartentry
139\global\let\blankpartentry=\dosmallblankpartentry
140@end tex
141@summarycontents
142
143@tex
144\global\let\partentry=\dopartentry
145\global\let\blankpartentry=\doblankpartentry
146@end tex
147@contents
148
149@page
150
151@c ---------------------------------------------------------------------
152@c TexInfo table of contents.
153@c ---------------------------------------------------------------------
154
155@ifnottex
156@node Top
157@top Introduction
158@cindex Introduction
159
160This manual documents the use of @command{gfortran},
161the GNU Fortran compiler.  You can find in this manual how to invoke
162@command{gfortran}, as well as its features and incompatibilities.
163
164@ifset DEVELOPMENT
165@emph{Warning:} This document, and the compiler it describes, are still
166under development.  While efforts are made to keep it up-to-date, it might
167not accurately reflect the status of the most recent GNU Fortran compiler.
168@end ifset
169
170@comment
171@comment  When you add a new menu item, please keep the right hand
172@comment  aligned to the same column.  Do not use tabs.  This provides
173@comment  better formatting.
174@comment
175@menu
176* Introduction::
177
178Part I: Invoking GNU Fortran
179* Invoking GNU Fortran:: Command options supported by @command{gfortran}.
180* Runtime::              Influencing runtime behavior with environment variables.
181
182Part II: Language Reference
183* Fortran 2003 and 2008 status::  Fortran 2003 and 2008 features supported by GNU Fortran.
184* Compiler Characteristics::      User-visible implementation details.
185* Extensions::                    Language extensions implemented by GNU Fortran.
186* Mixed-Language Programming::    Interoperability with C
187* Intrinsic Procedures:: Intrinsic procedures supported by GNU Fortran.
188* Intrinsic Modules::    Intrinsic modules supported by GNU Fortran.
189
190* Contributing::         How you can help.
191* Copying::              GNU General Public License says
192                         how you can copy and share GNU Fortran.
193* GNU Free Documentation License::
194                         How you can copy and share this manual.
195* Funding::              How to help assure continued work for free software.
196* Option Index::         Index of command line options
197* Keyword Index::        Index of concepts
198@end menu
199@end ifnottex
200
201@c ---------------------------------------------------------------------
202@c Introduction
203@c ---------------------------------------------------------------------
204
205@node Introduction
206@chapter Introduction
207
208@c The following duplicates the text on the TexInfo table of contents.
209@iftex
210This manual documents the use of @command{gfortran}, the GNU Fortran
211compiler.  You can find in this manual how to invoke @command{gfortran},
212as well as its features and incompatibilities.
213
214@ifset DEVELOPMENT
215@emph{Warning:} This document, and the compiler it describes, are still
216under development.  While efforts are made to keep it up-to-date, it
217might not accurately reflect the status of the most recent GNU Fortran
218compiler.
219@end ifset
220@end iftex
221
222The GNU Fortran compiler front end was
223designed initially as a free replacement for,
224or alternative to, the Unix @command{f95} command;
225@command{gfortran} is the command you will use to invoke the compiler.
226
227@menu
228* About GNU Fortran::    What you should know about the GNU Fortran compiler.
229* GNU Fortran and GCC::  You can compile Fortran, C, or other programs.
230* Preprocessing and conditional compilation:: The Fortran preprocessor
231* GNU Fortran and G77::  Why we chose to start from scratch.
232* Project Status::       Status of GNU Fortran, roadmap, proposed extensions.
233* Standards::            Standards supported by GNU Fortran.
234@end menu
235
236
237@c ---------------------------------------------------------------------
238@c About GNU Fortran
239@c ---------------------------------------------------------------------
240
241@node About GNU Fortran
242@section About GNU Fortran
243
244The GNU Fortran compiler supports the Fortran 77, 90 and 95 standards
245completely, parts of the Fortran 2003 and Fortran 2008 standards, and
246several vendor extensions.  The development goal is to provide the
247following features:
248
249@itemize @bullet
250@item
251Read a user's program,
252stored in a file and containing instructions written
253in Fortran 77, Fortran 90, Fortran 95, Fortran 2003 or Fortran 2008.
254This file contains @dfn{source code}.
255
256@item
257Translate the user's program into instructions a computer
258can carry out more quickly than it takes to translate the
259instructions in the first
260place.  The result after compilation of a program is
261@dfn{machine code},
262code designed to be efficiently translated and processed
263by a machine such as your computer.
264Humans usually are not as good writing machine code
265as they are at writing Fortran (or C++, Ada, or Java),
266because it is easy to make tiny mistakes writing machine code.
267
268@item
269Provide the user with information about the reasons why
270the compiler is unable to create a binary from the source code.
271Usually this will be the case if the source code is flawed.
272The Fortran 90 standard requires that the compiler can point out
273mistakes to the user.
274An incorrect usage of the language causes an @dfn{error message}.
275
276The compiler will also attempt to diagnose cases where the
277user's program contains a correct usage of the language,
278but instructs the computer to do something questionable.
279This kind of diagnostics message is called a @dfn{warning message}.
280
281@item
282Provide optional information about the translation passes
283from the source code to machine code.
284This can help a user of the compiler to find the cause of
285certain bugs which may not be obvious in the source code,
286but may be more easily found at a lower level compiler output.
287It also helps developers to find bugs in the compiler itself.
288
289@item
290Provide information in the generated machine code that can
291make it easier to find bugs in the program (using a debugging tool,
292called a @dfn{debugger}, such as the GNU Debugger @command{gdb}).
293
294@item
295Locate and gather machine code already generated to
296perform actions requested by statements in the user's program.
297This machine code is organized into @dfn{modules} and is located
298and @dfn{linked} to the user program.
299@end itemize
300
301The GNU Fortran compiler consists of several components:
302
303@itemize @bullet
304@item
305A version of the @command{gcc} command
306(which also might be installed as the system's @command{cc} command)
307that also understands and accepts Fortran source code.
308The @command{gcc} command is the @dfn{driver} program for
309all the languages in the GNU Compiler Collection (GCC);
310With @command{gcc},
311you can compile the source code of any language for
312which a front end is available in GCC.
313
314@item
315The @command{gfortran} command itself,
316which also might be installed as the
317system's @command{f95} command.
318@command{gfortran} is just another driver program,
319but specifically for the Fortran compiler only.
320The difference with @command{gcc} is that @command{gfortran}
321will automatically link the correct libraries to your program.
322
323@item
324A collection of run-time libraries.
325These libraries contain the machine code needed to support
326capabilities of the Fortran language that are not directly
327provided by the machine code generated by the
328@command{gfortran} compilation phase,
329such as intrinsic functions and subroutines,
330and routines for interaction with files and the operating system.
331@c and mechanisms to spawn,
332@c unleash and pause threads in parallelized code.
333
334@item
335The Fortran compiler itself, (@command{f951}).
336This is the GNU Fortran parser and code generator,
337linked to and interfaced with the GCC backend library.
338@command{f951} ``translates'' the source code to
339assembler code.  You would typically not use this
340program directly;
341instead, the @command{gcc} or @command{gfortran} driver
342programs will call it for you.
343@end itemize
344
345
346@c ---------------------------------------------------------------------
347@c GNU Fortran and GCC
348@c ---------------------------------------------------------------------
349
350@node GNU Fortran and GCC
351@section GNU Fortran and GCC
352@cindex GNU Compiler Collection
353@cindex GCC
354
355GNU Fortran is a part of GCC, the @dfn{GNU Compiler Collection}.  GCC
356consists of a collection of front ends for various languages, which
357translate the source code into a language-independent form called
358@dfn{GENERIC}.  This is then processed by a common middle end which
359provides optimization, and then passed to one of a collection of back
360ends which generate code for different computer architectures and
361operating systems.
362
363Functionally, this is implemented with a driver program (@command{gcc})
364which provides the command-line interface for the compiler.  It calls
365the relevant compiler front-end program (e.g., @command{f951} for
366Fortran) for each file in the source code, and then calls the assembler
367and linker as appropriate to produce the compiled output.  In a copy of
368GCC which has been compiled with Fortran language support enabled,
369@command{gcc} will recognize files with @file{.f}, @file{.for}, @file{.ftn},
370@file{.f90}, @file{.f95}, @file{.f03} and @file{.f08} extensions as
371Fortran source code, and compile it accordingly.  A @command{gfortran}
372driver program is also provided, which is identical to @command{gcc}
373except that it automatically links the Fortran runtime libraries into the
374compiled program.
375
376Source files with @file{.f}, @file{.for}, @file{.fpp}, @file{.ftn}, @file{.F},
377@file{.FOR}, @file{.FPP}, and @file{.FTN} extensions are treated as fixed form.
378Source files with @file{.f90}, @file{.f95}, @file{.f03}, @file{.f08},
379@file{.F90}, @file{.F95}, @file{.F03} and @file{.F08} extensions are
380treated as free form.  The capitalized versions of either form are run
381through preprocessing.  Source files with the lower case @file{.fpp}
382extension are also run through preprocessing.
383
384This manual specifically documents the Fortran front end, which handles
385the programming language's syntax and semantics.  The aspects of GCC
386which relate to the optimization passes and the back-end code generation
387are documented in the GCC manual; see
388@ref{Top,,Introduction,gcc,Using the GNU Compiler Collection (GCC)}.
389The two manuals together provide a complete reference for the GNU
390Fortran compiler.
391
392
393@c ---------------------------------------------------------------------
394@c Preprocessing and conditional compilation
395@c ---------------------------------------------------------------------
396
397@node Preprocessing and conditional compilation
398@section Preprocessing and conditional compilation
399@cindex CPP
400@cindex FPP
401@cindex Conditional compilation
402@cindex Preprocessing
403@cindex preprocessor, include file handling
404
405Many Fortran compilers including GNU Fortran allow passing the source code
406through a C preprocessor (CPP; sometimes also called the Fortran preprocessor,
407FPP) to allow for conditional compilation.  In the case of GNU Fortran,
408this is the GNU C Preprocessor in the traditional mode.  On systems with
409case-preserving file names, the preprocessor is automatically invoked if the
410filename extension is @file{.F}, @file{.FOR}, @file{.FTN}, @file{.fpp},
411@file{.FPP}, @file{.F90}, @file{.F95}, @file{.F03} or @file{.F08}.  To manually
412invoke the preprocessor on any file, use @option{-cpp}, to disable
413preprocessing on files where the preprocessor is run automatically, use
414@option{-nocpp}.
415
416If a preprocessed file includes another file with the Fortran @code{INCLUDE}
417statement, the included file is not preprocessed.  To preprocess included
418files, use the equivalent preprocessor statement @code{#include}.
419
420If GNU Fortran invokes the preprocessor, @code{__GFORTRAN__}
421is defined and @code{__GNUC__}, @code{__GNUC_MINOR__} and
422@code{__GNUC_PATCHLEVEL__} can be used to determine the version of the
423compiler.  See @ref{Top,,Overview,cpp,The C Preprocessor} for details.
424
425While CPP is the de-facto standard for preprocessing Fortran code,
426Part 3 of the Fortran 95 standard (ISO/IEC 1539-3:1998) defines
427Conditional Compilation, which is not widely used and not directly
428supported by the GNU Fortran compiler.  You can use the program coco
429to preprocess such files (@uref{http://www.daniellnagle.com/coco.html}).
430
431
432@c ---------------------------------------------------------------------
433@c GNU Fortran and G77
434@c ---------------------------------------------------------------------
435
436@node GNU Fortran and G77
437@section GNU Fortran and G77
438@cindex Fortran 77
439@cindex @command{g77}
440
441The GNU Fortran compiler is the successor to @command{g77}, the Fortran
44277 front end included in GCC prior to version 4.  It is an entirely new
443program that has been designed to provide Fortran 95 support and
444extensibility for future Fortran language standards, as well as providing
445backwards compatibility for Fortran 77 and nearly all of the GNU language
446extensions supported by @command{g77}.
447
448
449@c ---------------------------------------------------------------------
450@c Project Status
451@c ---------------------------------------------------------------------
452
453@node Project Status
454@section Project Status
455
456@quotation
457As soon as @command{gfortran} can parse all of the statements correctly,
458it will be in the ``larva'' state.
459When we generate code, the ``puppa'' state.
460When @command{gfortran} is done,
461we'll see if it will be a beautiful butterfly,
462or just a big bug....
463
464--Andy Vaught, April 2000
465@end quotation
466
467The start of the GNU Fortran 95 project was announced on
468the GCC homepage in March 18, 2000
469(even though Andy had already been working on it for a while,
470of course).
471
472The GNU Fortran compiler is able to compile nearly all
473standard-compliant Fortran 95, Fortran 90, and Fortran 77 programs,
474including a number of standard and non-standard extensions, and can be
475used on real-world programs.  In particular, the supported extensions
476include OpenMP, Cray-style pointers, and several Fortran 2003 and Fortran
4772008 features, including TR 15581.  However, it is still under
478development and has a few remaining rough edges.
479
480At present, the GNU Fortran compiler passes the
481@uref{http://www.fortran-2000.com/ArnaudRecipes/fcvs21_f95.html,
482NIST Fortran 77 Test Suite}, and produces acceptable results on the
483@uref{http://www.netlib.org/lapack/faq.html#1.21, LAPACK Test Suite}.
484It also provides respectable performance on
485the @uref{http://www.polyhedron.com/pb05.html, Polyhedron Fortran
486compiler benchmarks} and the
487@uref{http://www.llnl.gov/asci_benchmarks/asci/limited/lfk/README.html,
488Livermore Fortran Kernels test}.  It has been used to compile a number of
489large real-world programs, including
490@uref{http://mysite.verizon.net/serveall/moene.pdf, the HIRLAM
491weather-forecasting code} and
492@uref{http://www.theochem.uwa.edu.au/tonto/, the Tonto quantum
493chemistry package}; see @url{http://gcc.gnu.org/@/wiki/@/GfortranApps} for an
494extended list.
495
496Among other things, the GNU Fortran compiler is intended as a replacement
497for G77.  At this point, nearly all programs that could be compiled with
498G77 can be compiled with GNU Fortran, although there are a few minor known
499regressions.
500
501The primary work remaining to be done on GNU Fortran falls into three
502categories: bug fixing (primarily regarding the treatment of invalid code
503and providing useful error messages), improving the compiler optimizations
504and the performance of compiled code, and extending the compiler to support
505future standards---in particular, Fortran 2003 and Fortran 2008.
506
507
508@c ---------------------------------------------------------------------
509@c Standards
510@c ---------------------------------------------------------------------
511
512@node Standards
513@section Standards
514@cindex Standards
515
516@menu
517* Varying Length Character Strings::
518@end menu
519
520The GNU Fortran compiler implements
521ISO/IEC 1539:1997 (Fortran 95).  As such, it can also compile essentially all
522standard-compliant Fortran 90 and Fortran 77 programs.   It also supports
523the ISO/IEC TR-15581 enhancements to allocatable arrays.
524
525GNU Fortran also have a partial support for ISO/IEC 1539-1:2004 (Fortran
5262003), ISO/IEC 1539-1:2010 (Fortran 2008), the Technical Specification
527@code{Further Interoperability of Fortran with C} (ISO/IEC TS 29113:2012).
528Full support of those standards and future Fortran standards is planned.
529The current status of the support is can be found in the
530@ref{Fortran 2003 status}, @ref{Fortran 2008 status} and
531@ref{TS 29113 status} sections of the documentation.
532
533Additionally, the GNU Fortran compilers supports the OpenMP specification
534(version 3.1, @url{http://openmp.org/@/wp/@/openmp-specifications/}).
535
536@node Varying Length Character Strings
537@subsection Varying Length Character Strings
538@cindex Varying length character strings
539@cindex Varying length strings
540@cindex strings, varying length
541
542The Fortran 95 standard specifies in Part 2 (ISO/IEC 1539-2:2000)
543varying length character strings.  While GNU Fortran currently does not
544support such strings directly, there exist two Fortran implementations
545for them, which work with GNU Fortran.  They can be found at
546@uref{http://www.fortran.com/@/iso_varying_string.f95} and at
547@uref{ftp://ftp.nag.co.uk/@/sc22wg5/@/ISO_VARYING_STRING/}.
548
549Deferred-length character strings of Fortran 2003 supports part of
550the features of @code{ISO_VARYING_STRING} and should be considered as
551replacement. (Namely, allocatable or pointers of the type
552@code{character(len=:)}.)
553
554
555@c =====================================================================
556@c PART I: INVOCATION REFERENCE
557@c =====================================================================
558
559@tex
560\part{I}{Invoking GNU Fortran}
561@end tex
562
563@c ---------------------------------------------------------------------
564@c Compiler Options
565@c ---------------------------------------------------------------------
566
567@include invoke.texi
568
569
570@c ---------------------------------------------------------------------
571@c Runtime
572@c ---------------------------------------------------------------------
573
574@node Runtime
575@chapter Runtime:  Influencing runtime behavior with environment variables
576@cindex environment variable
577
578The behavior of the @command{gfortran} can be influenced by
579environment variables.
580
581Malformed environment variables are silently ignored.
582
583@menu
584* TMPDIR:: Directory for scratch files
585* GFORTRAN_STDIN_UNIT:: Unit number for standard input
586* GFORTRAN_STDOUT_UNIT:: Unit number for standard output
587* GFORTRAN_STDERR_UNIT:: Unit number for standard error
588* GFORTRAN_UNBUFFERED_ALL:: Do not buffer I/O for all units.
589* GFORTRAN_UNBUFFERED_PRECONNECTED:: Do not buffer I/O for preconnected units.
590* GFORTRAN_SHOW_LOCUS::  Show location for runtime errors
591* GFORTRAN_OPTIONAL_PLUS:: Print leading + where permitted
592* GFORTRAN_DEFAULT_RECL:: Default record length for new files
593* GFORTRAN_LIST_SEPARATOR::  Separator for list output
594* GFORTRAN_CONVERT_UNIT::  Set endianness for unformatted I/O
595* GFORTRAN_ERROR_BACKTRACE:: Show backtrace on run-time errors
596@end menu
597
598@node TMPDIR
599@section @env{TMPDIR}---Directory for scratch files
600
601When opening a file with @code{STATUS='SCRATCH'}, GNU Fortran tries to
602create the file in one of the potential directories by testing each
603directory in the order below.
604
605@enumerate
606@item
607The environment variable @env{TMPDIR}, if it exists.
608
609@item
610On the MinGW target, the directory returned by the @code{GetTempPath}
611function. Alternatively, on the Cygwin target, the @env{TMP} and
612@env{TEMP} environment variables, if they exist, in that order.
613
614@item
615The @code{P_tmpdir} macro if it is defined, otherwise the directory
616@file{/tmp}.
617@end enumerate
618
619@node GFORTRAN_STDIN_UNIT
620@section @env{GFORTRAN_STDIN_UNIT}---Unit number for standard input
621
622This environment variable can be used to select the unit number
623preconnected to standard input.  This must be a positive integer.
624The default value is 5.
625
626@node GFORTRAN_STDOUT_UNIT
627@section @env{GFORTRAN_STDOUT_UNIT}---Unit number for standard output
628
629This environment variable can be used to select the unit number
630preconnected to standard output.  This must be a positive integer.
631The default value is 6.
632
633@node GFORTRAN_STDERR_UNIT
634@section @env{GFORTRAN_STDERR_UNIT}---Unit number for standard error
635
636This environment variable can be used to select the unit number
637preconnected to standard error.  This must be a positive integer.
638The default value is 0.
639
640@node GFORTRAN_UNBUFFERED_ALL
641@section @env{GFORTRAN_UNBUFFERED_ALL}---Do not buffer I/O on all units
642
643This environment variable controls whether all I/O is unbuffered.  If
644the first letter is @samp{y}, @samp{Y} or @samp{1}, all I/O is
645unbuffered.  This will slow down small sequential reads and writes.  If
646the first letter is @samp{n}, @samp{N} or @samp{0}, I/O is buffered.
647This is the default.
648
649@node GFORTRAN_UNBUFFERED_PRECONNECTED
650@section @env{GFORTRAN_UNBUFFERED_PRECONNECTED}---Do not buffer I/O on preconnected units
651
652The environment variable named @env{GFORTRAN_UNBUFFERED_PRECONNECTED} controls
653whether I/O on a preconnected unit (i.e.@: STDOUT or STDERR) is unbuffered.  If
654the first letter is @samp{y}, @samp{Y} or @samp{1}, I/O is unbuffered.  This
655will slow down small sequential reads and writes.  If the first letter
656is @samp{n}, @samp{N} or @samp{0}, I/O is buffered.  This is the default.
657
658@node GFORTRAN_SHOW_LOCUS
659@section @env{GFORTRAN_SHOW_LOCUS}---Show location for runtime errors
660
661If the first letter is @samp{y}, @samp{Y} or @samp{1}, filename and
662line numbers for runtime errors are printed.  If the first letter is
663@samp{n}, @samp{N} or @samp{0}, do not print filename and line numbers
664for runtime errors.  The default is to print the location.
665
666@node GFORTRAN_OPTIONAL_PLUS
667@section @env{GFORTRAN_OPTIONAL_PLUS}---Print leading + where permitted
668
669If the first letter is @samp{y}, @samp{Y} or @samp{1},
670a plus sign is printed
671where permitted by the Fortran standard.  If the first letter
672is @samp{n}, @samp{N} or @samp{0}, a plus sign is not printed
673in most cases.  Default is not to print plus signs.
674
675@node GFORTRAN_DEFAULT_RECL
676@section @env{GFORTRAN_DEFAULT_RECL}---Default record length for new files
677
678This environment variable specifies the default record length, in
679bytes, for files which are opened without a @code{RECL} tag in the
680@code{OPEN} statement.  This must be a positive integer.  The
681default value is 1073741824 bytes (1 GB).
682
683@node GFORTRAN_LIST_SEPARATOR
684@section @env{GFORTRAN_LIST_SEPARATOR}---Separator for list output
685
686This environment variable specifies the separator when writing
687list-directed output.  It may contain any number of spaces and
688at most one comma.  If you specify this on the command line,
689be sure to quote spaces, as in
690@smallexample
691$ GFORTRAN_LIST_SEPARATOR='  ,  ' ./a.out
692@end smallexample
693when @command{a.out} is the compiled Fortran program that you want to run.
694Default is a single space.
695
696@node GFORTRAN_CONVERT_UNIT
697@section @env{GFORTRAN_CONVERT_UNIT}---Set endianness for unformatted I/O
698
699By setting the @env{GFORTRAN_CONVERT_UNIT} variable, it is possible
700to change the representation of data for unformatted files.
701The syntax for the @env{GFORTRAN_CONVERT_UNIT} variable is:
702@smallexample
703GFORTRAN_CONVERT_UNIT: mode | mode ';' exception | exception ;
704mode: 'native' | 'swap' | 'big_endian' | 'little_endian' ;
705exception: mode ':' unit_list | unit_list ;
706unit_list: unit_spec | unit_list unit_spec ;
707unit_spec: INTEGER | INTEGER '-' INTEGER ;
708@end smallexample
709The variable consists of an optional default mode, followed by
710a list of optional exceptions, which are separated by semicolons
711from the preceding default and each other.  Each exception consists
712of a format and a comma-separated list of units.  Valid values for
713the modes are the same as for the @code{CONVERT} specifier:
714
715@itemize @w{}
716@item @code{NATIVE} Use the native format.  This is the default.
717@item @code{SWAP} Swap between little- and big-endian.
718@item @code{LITTLE_ENDIAN} Use the little-endian format
719for unformatted files.
720@item @code{BIG_ENDIAN} Use the big-endian format for unformatted files.
721@end itemize
722A missing mode for an exception is taken to mean @code{BIG_ENDIAN}.
723Examples of values for @env{GFORTRAN_CONVERT_UNIT} are:
724@itemize @w{}
725@item @code{'big_endian'}  Do all unformatted I/O in big_endian mode.
726@item @code{'little_endian;native:10-20,25'}  Do all unformatted I/O
727in little_endian mode, except for units 10 to 20 and 25, which are in
728native format.
729@item @code{'10-20'}  Units 10 to 20 are big-endian, the rest is native.
730@end itemize
731
732Setting the environment variables should be done on the command
733line or via the @command{export}
734command for @command{sh}-compatible shells and via @command{setenv}
735for @command{csh}-compatible shells.
736
737Example for @command{sh}:
738@smallexample
739$ gfortran foo.f90
740$ GFORTRAN_CONVERT_UNIT='big_endian;native:10-20' ./a.out
741@end smallexample
742
743Example code for @command{csh}:
744@smallexample
745% gfortran foo.f90
746% setenv GFORTRAN_CONVERT_UNIT 'big_endian;native:10-20'
747% ./a.out
748@end smallexample
749
750Using anything but the native representation for unformatted data
751carries a significant speed overhead.  If speed in this area matters
752to you, it is best if you use this only for data that needs to be
753portable.
754
755@xref{CONVERT specifier}, for an alternative way to specify the
756data representation for unformatted files.  @xref{Runtime Options}, for
757setting a default data representation for the whole program.  The
758@code{CONVERT} specifier overrides the @option{-fconvert} compile options.
759
760@emph{Note that the values specified via the GFORTRAN_CONVERT_UNIT
761environment variable will override the CONVERT specifier in the
762open statement}.  This is to give control over data formats to
763users who do not have the source code of their program available.
764
765@node GFORTRAN_ERROR_BACKTRACE
766@section @env{GFORTRAN_ERROR_BACKTRACE}---Show backtrace on run-time errors
767
768If the @env{GFORTRAN_ERROR_BACKTRACE} variable is set to @samp{y},
769@samp{Y} or @samp{1} (only the first letter is relevant) then a
770backtrace is printed when a serious run-time error occurs.  To disable
771the backtracing, set the variable to @samp{n}, @samp{N}, @samp{0}.
772Default is to print a backtrace unless the @option{-fno-backtrace}
773compile option was used.
774
775@c =====================================================================
776@c PART II: LANGUAGE REFERENCE
777@c =====================================================================
778
779@tex
780\part{II}{Language Reference}
781@end tex
782
783@c ---------------------------------------------------------------------
784@c Fortran 2003 and 2008 Status
785@c ---------------------------------------------------------------------
786
787@node Fortran 2003 and 2008 status
788@chapter Fortran 2003 and 2008 Status
789
790@menu
791* Fortran 2003 status::
792* Fortran 2008 status::
793* TS 29113 status::
794@end menu
795
796@node Fortran 2003 status
797@section Fortran 2003 status
798
799GNU Fortran supports several Fortran 2003 features; an incomplete
800list can be found below.  See also the
801@uref{http://gcc.gnu.org/wiki/Fortran2003, wiki page} about Fortran 2003.
802
803@itemize
804@item Procedure pointers including procedure-pointer components with
805@code{PASS} attribute.
806
807@item Procedures which are bound to a derived type (type-bound procedures)
808including @code{PASS}, @code{PROCEDURE} and @code{GENERIC}, and
809operators bound to a type.
810
811@item Abstract interfaces and type extension with the possibility to
812override type-bound procedures or to have deferred binding.
813
814@item Polymorphic entities (``@code{CLASS}'') for derived types -- including
815@code{SAME_TYPE_AS}, @code{EXTENDS_TYPE_OF} and @code{SELECT TYPE} for
816scalars and arrays, including unlimited polymorphism.
817
818@item Generic interface names, which have the same name as derived types,
819are now supported. This allows one to write constructor functions.  Note
820that Fortran does not support static constructor functions.  For static
821variables, only default initialization or structure-constructor
822initialization are available.
823
824@item The @code{ASSOCIATE} construct.
825
826@item Interoperability with C including enumerations,
827
828@item In structure constructors the components with default values may be
829omitted.
830
831@item Extensions to the @code{ALLOCATE} statement, allowing for a
832type-specification with type parameter and for allocation and initialization
833from a @code{SOURCE=} expression; @code{ALLOCATE} and @code{DEALLOCATE}
834optionally return an error message string via @code{ERRMSG=}.
835
836@item Reallocation on assignment: If an intrinsic assignment is
837used, an allocatable variable on the left-hand side is automatically allocated
838(if unallocated) or reallocated (if the shape is different). Currently, scalar
839deferred character length left-hand sides are correctly handled but arrays
840are not yet fully implemented.
841
842@item Transferring of allocations via @code{MOVE_ALLOC}.
843
844@item The @code{PRIVATE} and @code{PUBLIC} attributes may be given individually
845to derived-type components.
846
847@item In pointer assignments, the lower bound may be specified and
848the remapping of elements is supported.
849
850@item For pointers an @code{INTENT} may be specified which affect the
851association status not the value of the pointer target.
852
853@item Intrinsics @code{command_argument_count}, @code{get_command},
854@code{get_command_argument}, and @code{get_environment_variable}.
855
856@item Support for Unicode characters (ISO 10646) and UTF-8, including
857the @code{SELECTED_CHAR_KIND} and @code{NEW_LINE} intrinsic functions.
858
859@item Support for binary, octal and hexadecimal (BOZ) constants in the
860intrinsic functions @code{INT}, @code{REAL}, @code{CMPLX} and @code{DBLE}.
861
862@item Support for namelist variables with allocatable and pointer
863attribute and nonconstant length type parameter.
864
865@item
866@cindex array, constructors
867@cindex @code{[...]}
868Array constructors using square brackets.  That is, @code{[...]} rather
869than @code{(/.../)}.  Type-specification for array constructors like
870@code{(/ some-type :: ... /)}.
871
872@item Extensions to the specification and initialization expressions,
873including the support for intrinsics with real and complex arguments.
874
875@item Support for the asynchronous input/output syntax; however, the
876data transfer is currently always synchronously performed.
877
878@item
879@cindex @code{FLUSH} statement
880@cindex statement, @code{FLUSH}
881@code{FLUSH} statement.
882
883@item
884@cindex @code{IOMSG=} specifier
885@code{IOMSG=} specifier for I/O statements.
886
887@item
888@cindex @code{ENUM} statement
889@cindex @code{ENUMERATOR} statement
890@cindex statement, @code{ENUM}
891@cindex statement, @code{ENUMERATOR}
892@opindex @code{fshort-enums}
893Support for the declaration of enumeration constants via the
894@code{ENUM} and @code{ENUMERATOR} statements.  Interoperability with
895@command{gcc} is guaranteed also for the case where the
896@command{-fshort-enums} command line option is given.
897
898@item
899@cindex TR 15581
900TR 15581:
901@itemize
902@item
903@cindex @code{ALLOCATABLE} dummy arguments
904@code{ALLOCATABLE} dummy arguments.
905@item
906@cindex @code{ALLOCATABLE} function results
907@code{ALLOCATABLE} function results
908@item
909@cindex @code{ALLOCATABLE} components of derived types
910@code{ALLOCATABLE} components of derived types
911@end itemize
912
913@item
914@cindex @code{STREAM} I/O
915@cindex @code{ACCESS='STREAM'} I/O
916The @code{OPEN} statement supports the @code{ACCESS='STREAM'} specifier,
917allowing I/O without any record structure.
918
919@item
920Namelist input/output for internal files.
921
922@item Further I/O extensions: Rounding during formatted output, using of
923a decimal comma instead of a decimal point, setting whether a plus sign
924should appear for positive numbers.
925
926@item
927@cindex @code{PROTECTED} statement
928@cindex statement, @code{PROTECTED}
929The @code{PROTECTED} statement and attribute.
930
931@item
932@cindex @code{VALUE} statement
933@cindex statement, @code{VALUE}
934The @code{VALUE} statement and attribute.
935
936@item
937@cindex @code{VOLATILE} statement
938@cindex statement, @code{VOLATILE}
939The @code{VOLATILE} statement and attribute.
940
941@item
942@cindex @code{IMPORT} statement
943@cindex statement, @code{IMPORT}
944The @code{IMPORT} statement, allowing to import
945host-associated derived types.
946
947@item The intrinsic modules @code{ISO_FORTRAN_ENVIRONMENT} is supported,
948which contains parameters of the I/O units, storage sizes. Additionally,
949procedures for C interoperability are available in the @code{ISO_C_BINDING}
950module.
951
952@item
953@cindex @code{USE, INTRINSIC} statement
954@cindex statement, @code{USE, INTRINSIC}
955@cindex @code{ISO_FORTRAN_ENV} statement
956@cindex statement, @code{ISO_FORTRAN_ENV}
957@code{USE} statement with @code{INTRINSIC} and @code{NON_INTRINSIC}
958attribute; supported intrinsic modules: @code{ISO_FORTRAN_ENV},
959@code{ISO_C_BINDING}, @code{OMP_LIB} and @code{OMP_LIB_KINDS}.
960
961@item
962Renaming of operators in the @code{USE} statement.
963
964@end itemize
965
966
967@node Fortran 2008 status
968@section Fortran 2008 status
969
970The latest version of the Fortran standard is ISO/IEC 1539-1:2010, informally
971known as Fortran 2008.  The official version is available from International
972Organization for Standardization (ISO) or its national member organizations.
973The the final draft (FDIS) can be downloaded free of charge from
974@url{http://www.nag.co.uk/@/sc22wg5/@/links.html}.  Fortran is developed by the
975Working Group 5 of Sub-Committee 22 of the Joint Technical Committee 1 of the
976International Organization for Standardization and the International
977Electrotechnical Commission (IEC).  This group is known as
978@uref{http://www.nag.co.uk/sc22wg5/, WG5}.
979
980The GNU Fortran compiler supports several of the new features of Fortran 2008;
981the @uref{http://gcc.gnu.org/wiki/Fortran2008Status, wiki} has some information
982about the current Fortran 2008 implementation status.  In particular, the
983following is implemented.
984
985@itemize
986@item The @option{-std=f2008} option and support for the file extensions
987@file{.f08} and @file{.F08}.
988
989@item The @code{OPEN} statement now supports the @code{NEWUNIT=} option,
990which returns a unique file unit, thus preventing inadvertent use of the
991same unit in different parts of the program.
992
993@item The @code{g0} format descriptor and unlimited format items.
994
995@item The mathematical intrinsics @code{ASINH}, @code{ACOSH}, @code{ATANH},
996@code{ERF}, @code{ERFC}, @code{GAMMA}, @code{LOG_GAMMA}, @code{BESSEL_J0},
997@code{BESSEL_J1}, @code{BESSEL_JN}, @code{BESSEL_Y0}, @code{BESSEL_Y1},
998@code{BESSEL_YN}, @code{HYPOT}, @code{NORM2}, and @code{ERFC_SCALED}.
999
1000@item Using complex arguments with @code{TAN}, @code{SINH}, @code{COSH},
1001@code{TANH}, @code{ASIN}, @code{ACOS}, and @code{ATAN} is now possible;
1002@code{ATAN}(@var{Y},@var{X}) is now an alias for @code{ATAN2}(@var{Y},@var{X}).
1003
1004@item Support of the @code{PARITY} intrinsic functions.
1005
1006@item The following bit intrinsics: @code{LEADZ} and @code{TRAILZ} for
1007counting the number of leading and trailing zero bits, @code{POPCNT} and
1008@code{POPPAR} for counting the number of one bits and returning the parity;
1009@code{BGE}, @code{BGT}, @code{BLE}, and @code{BLT} for bitwise comparisons;
1010@code{DSHIFTL} and @code{DSHIFTR} for combined left and right shifts,
1011@code{MASKL} and @code{MASKR} for simple left and right justified masks,
1012@code{MERGE_BITS} for a bitwise merge using a mask, @code{SHIFTA},
1013@code{SHIFTL} and @code{SHIFTR} for shift operations, and the
1014transformational bit intrinsics @code{IALL}, @code{IANY} and @code{IPARITY}.
1015
1016@item Support of the @code{EXECUTE_COMMAND_LINE} intrinsic subroutine.
1017
1018@item Support for the @code{STORAGE_SIZE} intrinsic inquiry function.
1019
1020@item The @code{INT@{8,16,32@}} and @code{REAL@{32,64,128@}} kind type
1021parameters and the array-valued named constants @code{INTEGER_KINDS},
1022@code{LOGICAL_KINDS}, @code{REAL_KINDS} and @code{CHARACTER_KINDS} of
1023the intrinsic module @code{ISO_FORTRAN_ENV}.
1024
1025@item The module procedures @code{C_SIZEOF} of the intrinsic module
1026@code{ISO_C_BINDINGS} and @code{COMPILER_VERSION} and @code{COMPILER_OPTIONS}
1027of @code{ISO_FORTRAN_ENV}.
1028
1029@item Coarray support for serial programs with @option{-fcoarray=single} flag
1030and experimental support for multiple images with the @option{-fcoarray=lib}
1031flag.
1032
1033@item The @code{DO CONCURRENT} construct is supported.
1034
1035@item The @code{BLOCK} construct is supported.
1036
1037@item The @code{STOP} and the new @code{ERROR STOP} statements now
1038support all constant expressions.
1039
1040@item Support for the @code{CONTIGUOUS} attribute.
1041
1042@item Support for @code{ALLOCATE} with @code{MOLD}.
1043
1044@item Support for the @code{IMPURE} attribute for procedures, which
1045allows for @code{ELEMENTAL} procedures without the restrictions of
1046@code{PURE}.
1047
1048@item Null pointers (including @code{NULL()}) and not-allocated variables
1049can be used as actual argument to optional non-pointer, non-allocatable
1050dummy arguments, denoting an absent argument.
1051
1052@item Non-pointer variables with @code{TARGET} attribute can be used as
1053actual argument to @code{POINTER} dummies with @code{INTENT(IN)}.
1054
1055@item Pointers including procedure pointers and those in a derived
1056type (pointer components) can now be initialized by a target instead
1057of only by @code{NULL}.
1058
1059@item The @code{EXIT} statement (with construct-name) can be now be
1060used to leave not only the @code{DO} but also the @code{ASSOCIATE},
1061@code{BLOCK}, @code{IF}, @code{SELECT CASE} and @code{SELECT TYPE}
1062constructs.
1063
1064@item Internal procedures can now be used as actual argument.
1065
1066@item Minor features: obsolesce diagnostics for @code{ENTRY} with
1067@option{-std=f2008}; a line may start with a semicolon; for internal
1068and module procedures @code{END} can be used instead of
1069@code{END SUBROUTINE} and @code{END FUNCTION}; @code{SELECTED_REAL_KIND}
1070now also takes a @code{RADIX} argument; intrinsic types are supported
1071for @code{TYPE}(@var{intrinsic-type-spec}); multiple type-bound procedures
1072can be declared in a single @code{PROCEDURE} statement; implied-shape
1073arrays are supported for named constants (@code{PARAMETER}).
1074@end itemize
1075
1076
1077
1078@node TS 29113 status
1079@section Technical Specification 29113 Status
1080
1081GNU Fortran supports some of the new features of the Technical
1082Specification (TS) 29113 on Further Interoperability of Fortran with C.
1083The @uref{http://gcc.gnu.org/wiki/TS29113Status, wiki} has some information
1084about the current TS 29113 implementation status.  In particular, the
1085following is implemented.
1086
1087See also @ref{Further Interoperability of Fortran with C}.
1088
1089@itemize
1090@item The @option{-std=f2008ts} option.
1091
1092@item The @code{OPTIONAL} attribute is allowed for dummy arguments
1093of @code{BIND(C) procedures.}
1094
1095@item The @code{RANK} intrinsic is supported.
1096
1097@item GNU Fortran's implementation for variables with @code{ASYNCHRONOUS}
1098attribute is compatible with TS 29113.
1099
1100@item Assumed types (@code{TYPE(*)}.
1101
1102@item Assumed-rank (@code{DIMENSION(..)}). However, the array descriptor
1103of the TS is not yet supported.
1104@end itemize
1105
1106
1107
1108@c ---------------------------------------------------------------------
1109@c Compiler Characteristics
1110@c ---------------------------------------------------------------------
1111
1112@node Compiler Characteristics
1113@chapter Compiler Characteristics
1114
1115This chapter describes certain characteristics of the GNU Fortran
1116compiler, that are not specified by the Fortran standard, but which
1117might in some way or another become visible to the programmer.
1118
1119@menu
1120* KIND Type Parameters::
1121* Internal representation of LOGICAL variables::
1122* Thread-safety of the runtime library::
1123* Data consistency and durability::
1124@end menu
1125
1126
1127@node KIND Type Parameters
1128@section KIND Type Parameters
1129@cindex kind
1130
1131The @code{KIND} type parameters supported by GNU Fortran for the primitive
1132data types are:
1133
1134@table @code
1135
1136@item INTEGER
11371, 2, 4, 8*, 16*, default: 4 (1)
1138
1139@item LOGICAL
11401, 2, 4, 8*, 16*, default: 4 (1)
1141
1142@item REAL
11434, 8, 10*, 16*, default: 4 (2)
1144
1145@item COMPLEX
11464, 8, 10*, 16*, default: 4 (2)
1147
1148@item CHARACTER
11491, 4, default: 1
1150
1151@end table
1152
1153@noindent
1154* = not available on all systems @*
1155(1) Unless -fdefault-integer-8 is used @*
1156(2) Unless -fdefault-real-8 is used
1157
1158@noindent
1159The @code{KIND} value matches the storage size in bytes, except for
1160@code{COMPLEX} where the storage size is twice as much (or both real and
1161imaginary part are a real value of the given size).  It is recommended to use
1162the @code{SELECTED_CHAR_KIND}, @code{SELECTED_INT_KIND} and
1163@code{SELECTED_REAL_KIND} intrinsics or the @code{INT8}, @code{INT16},
1164@code{INT32}, @code{INT64}, @code{REAL32}, @code{REAL64}, and @code{REAL128}
1165parameters of the @code{ISO_FORTRAN_ENV} module instead of the concrete values.
1166The available kind parameters can be found in the constant arrays
1167@code{CHARACTER_KINDS}, @code{INTEGER_KINDS}, @code{LOGICAL_KINDS} and
1168@code{REAL_KINDS} in the @code{ISO_FORTRAN_ENV} module
1169(see @ref{ISO_FORTRAN_ENV}).
1170
1171
1172@node Internal representation of LOGICAL variables
1173@section Internal representation of LOGICAL variables
1174@cindex logical, variable representation
1175
1176The Fortran standard does not specify how variables of @code{LOGICAL}
1177type are represented, beyond requiring that @code{LOGICAL} variables
1178of default kind have the same storage size as default @code{INTEGER}
1179and @code{REAL} variables.  The GNU Fortran internal representation is
1180as follows.
1181
1182A @code{LOGICAL(KIND=N)} variable is represented as an
1183@code{INTEGER(KIND=N)} variable, however, with only two permissible
1184values: @code{1} for @code{.TRUE.} and @code{0} for
1185@code{.FALSE.}.  Any other integer value results in undefined behavior.
1186
1187Note that for mixed-language programming using the
1188@code{ISO_C_BINDING} feature, there is a @code{C_BOOL} kind that can
1189be used to create @code{LOGICAL(KIND=C_BOOL)} variables which are
1190interoperable with the C99 _Bool type.  The C99 _Bool type has an
1191internal representation described in the C99 standard, which is
1192identical to the above description, i.e. with 1 for true and 0 for
1193false being the only permissible values.  Thus the internal
1194representation of @code{LOGICAL} variables in GNU Fortran is identical
1195to C99 _Bool, except for a possible difference in storage size
1196depending on the kind.
1197
1198
1199@node Thread-safety of the runtime library
1200@section Thread-safety of the runtime library
1201@cindex thread-safety, threads
1202
1203GNU Fortran can be used in programs with multiple threads, e.g.@: by
1204using OpenMP, by calling OS thread handling functions via the
1205@code{ISO_C_BINDING} facility, or by GNU Fortran compiled library code
1206being called from a multi-threaded program.
1207
1208The GNU Fortran runtime library, (@code{libgfortran}), supports being
1209called concurrently from multiple threads with the following
1210exceptions.
1211
1212During library initialization, the C @code{getenv} function is used,
1213which need not be thread-safe.  Similarly, the @code{getenv}
1214function is used to implement the @code{GET_ENVIRONMENT_VARIABLE} and
1215@code{GETENV} intrinsics.  It is the responsibility of the user to
1216ensure that the environment is not being updated concurrently when any
1217of these actions are taking place.
1218
1219The @code{EXECUTE_COMMAND_LINE} and @code{SYSTEM} intrinsics are
1220implemented with the @code{system} function, which need not be
1221thread-safe.  It is the responsibility of the user to ensure that
1222@code{system} is not called concurrently.
1223
1224Finally, for platforms not supporting thread-safe POSIX functions,
1225further functionality might not be thread-safe.  For details, please
1226consult the documentation for your operating system.
1227
1228
1229@node Data consistency and durability
1230@section Data consistency and durability
1231@cindex consistency, durability
1232
1233This section contains a brief overview of data and metadata
1234consistency and durability issues when doing I/O.
1235
1236With respect to durability, GNU Fortran makes no effort to ensure that
1237data is committed to stable storage. If this is required, the GNU
1238Fortran programmer can use the intrinsic @code{FNUM} to retrieve the
1239low level file descriptor corresponding to an open Fortran unit. Then,
1240using e.g. the @code{ISO_C_BINDING} feature, one can call the
1241underlying system call to flush dirty data to stable storage, such as
1242@code{fsync} on POSIX, @code{_commit} on MingW, or @code{fcntl(fd,
1243F_FULLSYNC, 0)} on Mac OS X. The following example shows how to call
1244fsync:
1245
1246@smallexample
1247  ! Declare the interface for POSIX fsync function
1248  interface
1249    function fsync (fd) bind(c,name="fsync")
1250    use iso_c_binding, only: c_int
1251      integer(c_int), value :: fd
1252      integer(c_int) :: fsync
1253    end function fsync
1254  end interface
1255
1256  ! Variable declaration
1257  integer :: ret
1258
1259  ! Opening unit 10
1260  open (10,file="foo")
1261
1262  ! ...
1263  ! Perform I/O on unit 10
1264  ! ...
1265
1266  ! Flush and sync
1267  flush(10)
1268  ret = fsync(fnum(10))
1269
1270  ! Handle possible error
1271  if (ret /= 0) stop "Error calling FSYNC"
1272@end smallexample
1273
1274With respect to consistency, for regular files GNU Fortran uses
1275buffered I/O in order to improve performance. This buffer is flushed
1276automatically when full and in some other situations, e.g. when
1277closing a unit. It can also be explicitly flushed with the
1278@code{FLUSH} statement. Also, the buffering can be turned off with the
1279@code{GFORTRAN_UNBUFFERED_ALL} and
1280@code{GFORTRAN_UNBUFFERED_PRECONNECTED} environment variables. Special
1281files, such as terminals and pipes, are always unbuffered. Sometimes,
1282however, further things may need to be done in order to allow other
1283processes to see data that GNU Fortran has written, as follows.
1284
1285The Windows platform supports a relaxed metadata consistency model,
1286where file metadata is written to the directory lazily. This means
1287that, for instance, the @code{dir} command can show a stale size for a
1288file. One can force a directory metadata update by closing the unit,
1289or by calling @code{_commit} on the file descriptor. Note, though,
1290that @code{_commit} will force all dirty data to stable storage, which
1291is often a very slow operation.
1292
1293The Network File System (NFS) implements a relaxed consistency model
1294called open-to-close consistency. Closing a file forces dirty data and
1295metadata to be flushed to the server, and opening a file forces the
1296client to contact the server in order to revalidate cached
1297data. @code{fsync} will also force a flush of dirty data and metadata
1298to the server. Similar to @code{open} and @code{close}, acquiring and
1299releasing @code{fcntl} file locks, if the server supports them, will
1300also force cache validation and flushing dirty data and metadata.
1301
1302
1303@c ---------------------------------------------------------------------
1304@c Extensions
1305@c ---------------------------------------------------------------------
1306
1307@c Maybe this chapter should be merged with the 'Standards' section,
1308@c whenever that is written :-)
1309
1310@node Extensions
1311@chapter Extensions
1312@cindex extensions
1313
1314The two sections below detail the extensions to standard Fortran that are
1315implemented in GNU Fortran, as well as some of the popular or
1316historically important extensions that are not (or not yet) implemented.
1317For the latter case, we explain the alternatives available to GNU Fortran
1318users, including replacement by standard-conforming code or GNU
1319extensions.
1320
1321@menu
1322* Extensions implemented in GNU Fortran::
1323* Extensions not implemented in GNU Fortran::
1324@end menu
1325
1326
1327@node Extensions implemented in GNU Fortran
1328@section Extensions implemented in GNU Fortran
1329@cindex extensions, implemented
1330
1331GNU Fortran implements a number of extensions over standard
1332Fortran.  This chapter contains information on their syntax and
1333meaning.  There are currently two categories of GNU Fortran
1334extensions, those that provide functionality beyond that provided
1335by any standard, and those that are supported by GNU Fortran
1336purely for backward compatibility with legacy compilers.  By default,
1337@option{-std=gnu} allows the compiler to accept both types of
1338extensions, but to warn about the use of the latter.  Specifying
1339either @option{-std=f95}, @option{-std=f2003} or @option{-std=f2008}
1340disables both types of extensions, and @option{-std=legacy} allows both
1341without warning.
1342
1343@menu
1344* Old-style kind specifications::
1345* Old-style variable initialization::
1346* Extensions to namelist::
1347* X format descriptor without count field::
1348* Commas in FORMAT specifications::
1349* Missing period in FORMAT specifications::
1350* I/O item lists::
1351* @code{Q} exponent-letter::
1352* BOZ literal constants::
1353* Real array indices::
1354* Unary operators::
1355* Implicitly convert LOGICAL and INTEGER values::
1356* Hollerith constants support::
1357* Cray pointers::
1358* CONVERT specifier::
1359* OpenMP::
1360* Argument list functions::
1361@end menu
1362
1363@node Old-style kind specifications
1364@subsection Old-style kind specifications
1365@cindex kind, old-style
1366
1367GNU Fortran allows old-style kind specifications in declarations.  These
1368look like:
1369@smallexample
1370      TYPESPEC*size x,y,z
1371@end smallexample
1372@noindent
1373where @code{TYPESPEC} is a basic type (@code{INTEGER}, @code{REAL},
1374etc.), and where @code{size} is a byte count corresponding to the
1375storage size of a valid kind for that type.  (For @code{COMPLEX}
1376variables, @code{size} is the total size of the real and imaginary
1377parts.)  The statement then declares @code{x}, @code{y} and @code{z} to
1378be of type @code{TYPESPEC} with the appropriate kind.  This is
1379equivalent to the standard-conforming declaration
1380@smallexample
1381      TYPESPEC(k) x,y,z
1382@end smallexample
1383@noindent
1384where @code{k} is the kind parameter suitable for the intended precision.  As
1385kind parameters are implementation-dependent, use the @code{KIND},
1386@code{SELECTED_INT_KIND} and @code{SELECTED_REAL_KIND} intrinsics to retrieve
1387the correct value, for instance @code{REAL*8 x} can be replaced by:
1388@smallexample
1389INTEGER, PARAMETER :: dbl = KIND(1.0d0)
1390REAL(KIND=dbl) :: x
1391@end smallexample
1392
1393@node Old-style variable initialization
1394@subsection Old-style variable initialization
1395
1396GNU Fortran allows old-style initialization of variables of the
1397form:
1398@smallexample
1399      INTEGER i/1/,j/2/
1400      REAL x(2,2) /3*0.,1./
1401@end smallexample
1402The syntax for the initializers is as for the @code{DATA} statement, but
1403unlike in a @code{DATA} statement, an initializer only applies to the
1404variable immediately preceding the initialization.  In other words,
1405something like @code{INTEGER I,J/2,3/} is not valid.  This style of
1406initialization is only allowed in declarations without double colons
1407(@code{::}); the double colons were introduced in Fortran 90, which also
1408introduced a standard syntax for initializing variables in type
1409declarations.
1410
1411Examples of standard-conforming code equivalent to the above example
1412are:
1413@smallexample
1414! Fortran 90
1415      INTEGER :: i = 1, j = 2
1416      REAL :: x(2,2) = RESHAPE((/0.,0.,0.,1./),SHAPE(x))
1417! Fortran 77
1418      INTEGER i, j
1419      REAL x(2,2)
1420      DATA i/1/, j/2/, x/3*0.,1./
1421@end smallexample
1422
1423Note that variables which are explicitly initialized in declarations
1424or in @code{DATA} statements automatically acquire the @code{SAVE}
1425attribute.
1426
1427@node Extensions to namelist
1428@subsection Extensions to namelist
1429@cindex Namelist
1430
1431GNU Fortran fully supports the Fortran 95 standard for namelist I/O
1432including array qualifiers, substrings and fully qualified derived types.
1433The output from a namelist write is compatible with namelist read.  The
1434output has all names in upper case and indentation to column 1 after the
1435namelist name.  Two extensions are permitted:
1436
1437Old-style use of @samp{$} instead of @samp{&}
1438@smallexample
1439$MYNML
1440 X(:)%Y(2) = 1.0 2.0 3.0
1441 CH(1:4) = "abcd"
1442$END
1443@end smallexample
1444
1445It should be noted that the default terminator is @samp{/} rather than
1446@samp{&END}.
1447
1448Querying of the namelist when inputting from stdin.  After at least
1449one space, entering @samp{?} sends to stdout the namelist name and the names of
1450the variables in the namelist:
1451@smallexample
1452 ?
1453
1454&mynml
1455 x
1456 x%y
1457 ch
1458&end
1459@end smallexample
1460
1461Entering @samp{=?} outputs the namelist to stdout, as if
1462@code{WRITE(*,NML = mynml)} had been called:
1463@smallexample
1464=?
1465
1466&MYNML
1467 X(1)%Y=  0.000000    ,  1.000000    ,  0.000000    ,
1468 X(2)%Y=  0.000000    ,  2.000000    ,  0.000000    ,
1469 X(3)%Y=  0.000000    ,  3.000000    ,  0.000000    ,
1470 CH=abcd,  /
1471@end smallexample
1472
1473To aid this dialog, when input is from stdin, errors send their
1474messages to stderr and execution continues, even if @code{IOSTAT} is set.
1475
1476@code{PRINT} namelist is permitted.  This causes an error if
1477@option{-std=f95} is used.
1478@smallexample
1479PROGRAM test_print
1480  REAL, dimension (4)  ::  x = (/1.0, 2.0, 3.0, 4.0/)
1481  NAMELIST /mynml/ x
1482  PRINT mynml
1483END PROGRAM test_print
1484@end smallexample
1485
1486Expanded namelist reads are permitted.  This causes an error if
1487@option{-std=f95} is used.  In the following example, the first element
1488of the array will be given the value 0.00 and the two succeeding
1489elements will be given the values 1.00 and 2.00.
1490@smallexample
1491&MYNML
1492  X(1,1) = 0.00 , 1.00 , 2.00
1493/
1494@end smallexample
1495
1496@node X format descriptor without count field
1497@subsection @code{X} format descriptor without count field
1498
1499To support legacy codes, GNU Fortran permits the count field of the
1500@code{X} edit descriptor in @code{FORMAT} statements to be omitted.
1501When omitted, the count is implicitly assumed to be one.
1502
1503@smallexample
1504       PRINT 10, 2, 3
150510     FORMAT (I1, X, I1)
1506@end smallexample
1507
1508@node Commas in FORMAT specifications
1509@subsection Commas in @code{FORMAT} specifications
1510
1511To support legacy codes, GNU Fortran allows the comma separator
1512to be omitted immediately before and after character string edit
1513descriptors in @code{FORMAT} statements.
1514
1515@smallexample
1516       PRINT 10, 2, 3
151710     FORMAT ('FOO='I1' BAR='I2)
1518@end smallexample
1519
1520
1521@node Missing period in FORMAT specifications
1522@subsection Missing period in @code{FORMAT} specifications
1523
1524To support legacy codes, GNU Fortran allows missing periods in format
1525specifications if and only if @option{-std=legacy} is given on the
1526command line.  This is considered non-conforming code and is
1527discouraged.
1528
1529@smallexample
1530       REAL :: value
1531       READ(*,10) value
153210     FORMAT ('F4')
1533@end smallexample
1534
1535@node I/O item lists
1536@subsection I/O item lists
1537@cindex I/O item lists
1538
1539To support legacy codes, GNU Fortran allows the input item list
1540of the @code{READ} statement, and the output item lists of the
1541@code{WRITE} and @code{PRINT} statements, to start with a comma.
1542
1543@node @code{Q} exponent-letter
1544@subsection @code{Q} exponent-letter
1545@cindex @code{Q} exponent-letter
1546
1547GNU Fortran accepts real literal constants with an exponent-letter
1548of @code{Q}, for example, @code{1.23Q45}.  The constant is interpreted
1549as a @code{REAL(16)} entity on targets that support this type.  If
1550the target does not support @code{REAL(16)} but has a @code{REAL(10)}
1551type, then the real-literal-constant will be interpreted as a
1552@code{REAL(10)} entity.  In the absence of @code{REAL(16)} and
1553@code{REAL(10)}, an error will occur.
1554
1555@node BOZ literal constants
1556@subsection BOZ literal constants
1557@cindex BOZ literal constants
1558
1559Besides decimal constants, Fortran also supports binary (@code{b}),
1560octal (@code{o}) and hexadecimal (@code{z}) integer constants.  The
1561syntax is: @samp{prefix quote digits quote}, were the prefix is
1562either @code{b}, @code{o} or @code{z}, quote is either @code{'} or
1563@code{"} and the digits are for binary @code{0} or @code{1}, for
1564octal between @code{0} and @code{7}, and for hexadecimal between
1565@code{0} and @code{F}.  (Example: @code{b'01011101'}.)
1566
1567Up to Fortran 95, BOZ literals were only allowed to initialize
1568integer variables in DATA statements.  Since Fortran 2003 BOZ literals
1569are also allowed as argument of @code{REAL}, @code{DBLE}, @code{INT}
1570and @code{CMPLX}; the result is the same as if the integer BOZ
1571literal had been converted by @code{TRANSFER} to, respectively,
1572@code{real}, @code{double precision}, @code{integer} or @code{complex}.
1573As GNU Fortran extension the intrinsic procedures @code{FLOAT},
1574@code{DFLOAT}, @code{COMPLEX} and @code{DCMPLX} are treated alike.
1575
1576As an extension, GNU Fortran allows hexadecimal BOZ literal constants to
1577be specified using the @code{X} prefix, in addition to the standard
1578@code{Z} prefix.  The BOZ literal can also be specified by adding a
1579suffix to the string, for example, @code{Z'ABC'} and @code{'ABC'Z} are
1580equivalent.
1581
1582Furthermore, GNU Fortran allows using BOZ literal constants outside
1583DATA statements and the four intrinsic functions allowed by Fortran 2003.
1584In DATA statements, in direct assignments, where the right-hand side
1585only contains a BOZ literal constant, and for old-style initializers of
1586the form @code{integer i /o'0173'/}, the constant is transferred
1587as if @code{TRANSFER} had been used; for @code{COMPLEX} numbers, only
1588the real part is initialized unless @code{CMPLX} is used.  In all other
1589cases, the BOZ literal constant is converted to an @code{INTEGER} value with
1590the largest decimal representation.  This value is then converted
1591numerically to the type and kind of the variable in question.
1592(For instance, @code{real :: r = b'0000001' + 1} initializes @code{r}
1593with @code{2.0}.) As different compilers implement the extension
1594differently, one should be careful when doing bitwise initialization
1595of non-integer variables.
1596
1597Note that initializing an @code{INTEGER} variable with a statement such
1598as @code{DATA i/Z'FFFFFFFF'/} will give an integer overflow error rather
1599than the desired result of @math{-1} when @code{i} is a 32-bit integer
1600on a system that supports 64-bit integers.  The @samp{-fno-range-check}
1601option can be used as a workaround for legacy code that initializes
1602integers in this manner.
1603
1604@node Real array indices
1605@subsection Real array indices
1606@cindex array, indices of type real
1607
1608As an extension, GNU Fortran allows the use of @code{REAL} expressions
1609or variables as array indices.
1610
1611@node Unary operators
1612@subsection Unary operators
1613@cindex operators, unary
1614
1615As an extension, GNU Fortran allows unary plus and unary minus operators
1616to appear as the second operand of binary arithmetic operators without
1617the need for parenthesis.
1618
1619@smallexample
1620       X = Y * -Z
1621@end smallexample
1622
1623@node Implicitly convert LOGICAL and INTEGER values
1624@subsection Implicitly convert @code{LOGICAL} and @code{INTEGER} values
1625@cindex conversion, to integer
1626@cindex conversion, to logical
1627
1628As an extension for backwards compatibility with other compilers, GNU
1629Fortran allows the implicit conversion of @code{LOGICAL} values to
1630@code{INTEGER} values and vice versa.  When converting from a
1631@code{LOGICAL} to an @code{INTEGER}, @code{.FALSE.} is interpreted as
1632zero, and @code{.TRUE.} is interpreted as one.  When converting from
1633@code{INTEGER} to @code{LOGICAL}, the value zero is interpreted as
1634@code{.FALSE.} and any nonzero value is interpreted as @code{.TRUE.}.
1635
1636@smallexample
1637        LOGICAL :: l
1638        l = 1
1639@end smallexample
1640@smallexample
1641        INTEGER :: i
1642        i = .TRUE.
1643@end smallexample
1644
1645However, there is no implicit conversion of @code{INTEGER} values in
1646@code{if}-statements, nor of @code{LOGICAL} or @code{INTEGER} values
1647in I/O operations.
1648
1649@node Hollerith constants support
1650@subsection Hollerith constants support
1651@cindex Hollerith constants
1652
1653GNU Fortran supports Hollerith constants in assignments, function
1654arguments, and @code{DATA} and @code{ASSIGN} statements.  A Hollerith
1655constant is written as a string of characters preceded by an integer
1656constant indicating the character count, and the letter @code{H} or
1657@code{h}, and stored in bytewise fashion in a numeric (@code{INTEGER},
1658@code{REAL}, or @code{complex}) or @code{LOGICAL} variable.  The
1659constant will be padded or truncated to fit the size of the variable in
1660which it is stored.
1661
1662Examples of valid uses of Hollerith constants:
1663@smallexample
1664      complex*16 x(2)
1665      data x /16Habcdefghijklmnop, 16Hqrstuvwxyz012345/
1666      x(1) = 16HABCDEFGHIJKLMNOP
1667      call foo (4h abc)
1668@end smallexample
1669
1670Invalid Hollerith constants examples:
1671@smallexample
1672      integer*4 a
1673      a = 8H12345678 ! Valid, but the Hollerith constant will be truncated.
1674      a = 0H         ! At least one character is needed.
1675@end smallexample
1676
1677In general, Hollerith constants were used to provide a rudimentary
1678facility for handling character strings in early Fortran compilers,
1679prior to the introduction of @code{CHARACTER} variables in Fortran 77;
1680in those cases, the standard-compliant equivalent is to convert the
1681program to use proper character strings.  On occasion, there may be a
1682case where the intent is specifically to initialize a numeric variable
1683with a given byte sequence.  In these cases, the same result can be
1684obtained by using the @code{TRANSFER} statement, as in this example.
1685@smallexample
1686      INTEGER(KIND=4) :: a
1687      a = TRANSFER ("abcd", a)     ! equivalent to: a = 4Habcd
1688@end smallexample
1689
1690
1691@node Cray pointers
1692@subsection Cray pointers
1693@cindex pointer, Cray
1694
1695Cray pointers are part of a non-standard extension that provides a
1696C-like pointer in Fortran.  This is accomplished through a pair of
1697variables: an integer "pointer" that holds a memory address, and a
1698"pointee" that is used to dereference the pointer.
1699
1700Pointer/pointee pairs are declared in statements of the form:
1701@smallexample
1702        pointer ( <pointer> , <pointee> )
1703@end smallexample
1704or,
1705@smallexample
1706        pointer ( <pointer1> , <pointee1> ), ( <pointer2> , <pointee2> ), ...
1707@end smallexample
1708The pointer is an integer that is intended to hold a memory address.
1709The pointee may be an array or scalar.  A pointee can be an assumed
1710size array---that is, the last dimension may be left unspecified by
1711using a @code{*} in place of a value---but a pointee cannot be an
1712assumed shape array.  No space is allocated for the pointee.
1713
1714The pointee may have its type declared before or after the pointer
1715statement, and its array specification (if any) may be declared
1716before, during, or after the pointer statement.  The pointer may be
1717declared as an integer prior to the pointer statement.  However, some
1718machines have default integer sizes that are different than the size
1719of a pointer, and so the following code is not portable:
1720@smallexample
1721        integer ipt
1722        pointer (ipt, iarr)
1723@end smallexample
1724If a pointer is declared with a kind that is too small, the compiler
1725will issue a warning; the resulting binary will probably not work
1726correctly, because the memory addresses stored in the pointers may be
1727truncated.  It is safer to omit the first line of the above example;
1728if explicit declaration of ipt's type is omitted, then the compiler
1729will ensure that ipt is an integer variable large enough to hold a
1730pointer.
1731
1732Pointer arithmetic is valid with Cray pointers, but it is not the same
1733as C pointer arithmetic.  Cray pointers are just ordinary integers, so
1734the user is responsible for determining how many bytes to add to a
1735pointer in order to increment it.  Consider the following example:
1736@smallexample
1737        real target(10)
1738        real pointee(10)
1739        pointer (ipt, pointee)
1740        ipt = loc (target)
1741        ipt = ipt + 1
1742@end smallexample
1743The last statement does not set @code{ipt} to the address of
1744@code{target(1)}, as it would in C pointer arithmetic.  Adding @code{1}
1745to @code{ipt} just adds one byte to the address stored in @code{ipt}.
1746
1747Any expression involving the pointee will be translated to use the
1748value stored in the pointer as the base address.
1749
1750To get the address of elements, this extension provides an intrinsic
1751function @code{LOC()}.  The @code{LOC()} function is equivalent to the
1752@code{&} operator in C, except the address is cast to an integer type:
1753@smallexample
1754        real ar(10)
1755        pointer(ipt, arpte(10))
1756        real arpte
1757        ipt = loc(ar)  ! Makes arpte is an alias for ar
1758        arpte(1) = 1.0 ! Sets ar(1) to 1.0
1759@end smallexample
1760The pointer can also be set by a call to the @code{MALLOC} intrinsic
1761(see @ref{MALLOC}).
1762
1763Cray pointees often are used to alias an existing variable.  For
1764example:
1765@smallexample
1766        integer target(10)
1767        integer iarr(10)
1768        pointer (ipt, iarr)
1769        ipt = loc(target)
1770@end smallexample
1771As long as @code{ipt} remains unchanged, @code{iarr} is now an alias for
1772@code{target}.  The optimizer, however, will not detect this aliasing, so
1773it is unsafe to use @code{iarr} and @code{target} simultaneously.  Using
1774a pointee in any way that violates the Fortran aliasing rules or
1775assumptions is illegal.  It is the user's responsibility to avoid doing
1776this; the compiler works under the assumption that no such aliasing
1777occurs.
1778
1779Cray pointers will work correctly when there is no aliasing (i.e., when
1780they are used to access a dynamically allocated block of memory), and
1781also in any routine where a pointee is used, but any variable with which
1782it shares storage is not used.  Code that violates these rules may not
1783run as the user intends.  This is not a bug in the optimizer; any code
1784that violates the aliasing rules is illegal.  (Note that this is not
1785unique to GNU Fortran; any Fortran compiler that supports Cray pointers
1786will ``incorrectly'' optimize code with illegal aliasing.)
1787
1788There are a number of restrictions on the attributes that can be applied
1789to Cray pointers and pointees.  Pointees may not have the
1790@code{ALLOCATABLE}, @code{INTENT}, @code{OPTIONAL}, @code{DUMMY},
1791@code{TARGET}, @code{INTRINSIC}, or @code{POINTER} attributes.  Pointers
1792may not have the @code{DIMENSION}, @code{POINTER}, @code{TARGET},
1793@code{ALLOCATABLE}, @code{EXTERNAL}, or @code{INTRINSIC} attributes, nor
1794may they be function results.  Pointees may not occur in more than one
1795pointer statement.  A pointee cannot be a pointer.  Pointees cannot occur
1796in equivalence, common, or data statements.
1797
1798A Cray pointer may also point to a function or a subroutine.  For
1799example, the following excerpt is valid:
1800@smallexample
1801  implicit none
1802  external sub
1803  pointer (subptr,subpte)
1804  external subpte
1805  subptr = loc(sub)
1806  call subpte()
1807  [...]
1808  subroutine sub
1809  [...]
1810  end subroutine sub
1811@end smallexample
1812
1813A pointer may be modified during the course of a program, and this
1814will change the location to which the pointee refers.  However, when
1815pointees are passed as arguments, they are treated as ordinary
1816variables in the invoked function.  Subsequent changes to the pointer
1817will not change the base address of the array that was passed.
1818
1819@node CONVERT specifier
1820@subsection @code{CONVERT} specifier
1821@cindex @code{CONVERT} specifier
1822
1823GNU Fortran allows the conversion of unformatted data between little-
1824and big-endian representation to facilitate moving of data
1825between different systems.  The conversion can be indicated with
1826the @code{CONVERT} specifier on the @code{OPEN} statement.
1827@xref{GFORTRAN_CONVERT_UNIT}, for an alternative way of specifying
1828the data format via an environment variable.
1829
1830Valid values for @code{CONVERT} are:
1831@itemize @w{}
1832@item @code{CONVERT='NATIVE'} Use the native format.  This is the default.
1833@item @code{CONVERT='SWAP'} Swap between little- and big-endian.
1834@item @code{CONVERT='LITTLE_ENDIAN'} Use the little-endian representation
1835for unformatted files.
1836@item @code{CONVERT='BIG_ENDIAN'} Use the big-endian representation for
1837unformatted files.
1838@end itemize
1839
1840Using the option could look like this:
1841@smallexample
1842  open(file='big.dat',form='unformatted',access='sequential', &
1843       convert='big_endian')
1844@end smallexample
1845
1846The value of the conversion can be queried by using
1847@code{INQUIRE(CONVERT=ch)}.  The values returned are
1848@code{'BIG_ENDIAN'} and @code{'LITTLE_ENDIAN'}.
1849
1850@code{CONVERT} works between big- and little-endian for
1851@code{INTEGER} values of all supported kinds and for @code{REAL}
1852on IEEE systems of kinds 4 and 8.  Conversion between different
1853``extended double'' types on different architectures such as
1854m68k and x86_64, which GNU Fortran
1855supports as @code{REAL(KIND=10)} and @code{REAL(KIND=16)}, will
1856probably not work.
1857
1858@emph{Note that the values specified via the GFORTRAN_CONVERT_UNIT
1859environment variable will override the CONVERT specifier in the
1860open statement}.  This is to give control over data formats to
1861users who do not have the source code of their program available.
1862
1863Using anything but the native representation for unformatted data
1864carries a significant speed overhead.  If speed in this area matters
1865to you, it is best if you use this only for data that needs to be
1866portable.
1867
1868@node OpenMP
1869@subsection OpenMP
1870@cindex OpenMP
1871
1872OpenMP (Open Multi-Processing) is an application programming
1873interface (API) that supports multi-platform shared memory
1874multiprocessing programming in C/C++ and Fortran on many
1875architectures, including Unix and Microsoft Windows platforms.
1876It consists of a set of compiler directives, library routines,
1877and environment variables that influence run-time behavior.
1878
1879GNU Fortran strives to be compatible to the
1880@uref{http://www.openmp.org/mp-documents/spec31.pdf,
1881OpenMP Application Program Interface v3.1}.
1882
1883To enable the processing of the OpenMP directive @code{!$omp} in
1884free-form source code; the @code{c$omp}, @code{*$omp} and @code{!$omp}
1885directives in fixed form; the @code{!$} conditional compilation sentinels
1886in free form; and the @code{c$}, @code{*$} and @code{!$} sentinels
1887in fixed form, @command{gfortran} needs to be invoked with the
1888@option{-fopenmp}.  This also arranges for automatic linking of the
1889GNU OpenMP runtime library @ref{Top,,libgomp,libgomp,GNU OpenMP
1890runtime library}.
1891
1892The OpenMP Fortran runtime library routines are provided both in a
1893form of a Fortran 90 module named @code{omp_lib} and in a form of
1894a Fortran @code{include} file named @file{omp_lib.h}.
1895
1896An example of a parallelized loop taken from Appendix A.1 of
1897the OpenMP Application Program Interface v2.5:
1898@smallexample
1899SUBROUTINE A1(N, A, B)
1900  INTEGER I, N
1901  REAL B(N), A(N)
1902!$OMP PARALLEL DO !I is private by default
1903  DO I=2,N
1904    B(I) = (A(I) + A(I-1)) / 2.0
1905  ENDDO
1906!$OMP END PARALLEL DO
1907END SUBROUTINE A1
1908@end smallexample
1909
1910Please note:
1911@itemize
1912@item
1913@option{-fopenmp} implies @option{-frecursive}, i.e., all local arrays
1914will be allocated on the stack.  When porting existing code to OpenMP,
1915this may lead to surprising results, especially to segmentation faults
1916if the stacksize is limited.
1917
1918@item
1919On glibc-based systems, OpenMP enabled applications cannot be statically
1920linked due to limitations of the underlying pthreads-implementation.  It
1921might be possible to get a working solution if
1922@command{-Wl,--whole-archive -lpthread -Wl,--no-whole-archive} is added
1923to the command line.  However, this is not supported by @command{gcc} and
1924thus not recommended.
1925@end itemize
1926
1927@node Argument list functions
1928@subsection Argument list functions @code{%VAL}, @code{%REF} and @code{%LOC}
1929@cindex argument list functions
1930@cindex @code{%VAL}
1931@cindex @code{%REF}
1932@cindex @code{%LOC}
1933
1934GNU Fortran supports argument list functions @code{%VAL}, @code{%REF}
1935and @code{%LOC} statements, for backward compatibility with g77.
1936It is recommended that these should be used only for code that is
1937accessing facilities outside of GNU Fortran, such as operating system
1938or windowing facilities.  It is best to constrain such uses to isolated
1939portions of a program--portions that deal specifically and exclusively
1940with low-level, system-dependent facilities.  Such portions might well
1941provide a portable interface for use by the program as a whole, but are
1942themselves not portable, and should be thoroughly tested each time they
1943are rebuilt using a new compiler or version of a compiler.
1944
1945@code{%VAL} passes a scalar argument by value, @code{%REF} passes it by
1946reference and @code{%LOC} passes its memory location.  Since gfortran
1947already passes scalar arguments by reference, @code{%REF} is in effect
1948a do-nothing.  @code{%LOC} has the same effect as a Fortran pointer.
1949
1950An example of passing an argument by value to a C subroutine foo.:
1951@smallexample
1952C
1953C prototype      void foo_ (float x);
1954C
1955      external foo
1956      real*4 x
1957      x = 3.14159
1958      call foo (%VAL (x))
1959      end
1960@end smallexample
1961
1962For details refer to the g77 manual
1963@uref{http://gcc.gnu.org/@/onlinedocs/@/gcc-3.4.6/@/g77/@/index.html#Top}.
1964
1965Also, @code{c_by_val.f} and its partner @code{c_by_val.c} of the
1966GNU Fortran testsuite are worth a look.
1967
1968
1969@node Extensions not implemented in GNU Fortran
1970@section Extensions not implemented in GNU Fortran
1971@cindex extensions, not implemented
1972
1973The long history of the Fortran language, its wide use and broad
1974userbase, the large number of different compiler vendors and the lack of
1975some features crucial to users in the first standards have lead to the
1976existence of a number of important extensions to the language.  While
1977some of the most useful or popular extensions are supported by the GNU
1978Fortran compiler, not all existing extensions are supported.  This section
1979aims at listing these extensions and offering advice on how best make
1980code that uses them running with the GNU Fortran compiler.
1981
1982@c More can be found here:
1983@c   -- http://gcc.gnu.org/onlinedocs/gcc-3.4.6/g77/Missing-Features.html
1984@c   -- the list of Fortran and libgfortran bugs closed as WONTFIX:
1985@c      http://tinyurl.com/2u4h5y
1986
1987@menu
1988* STRUCTURE and RECORD::
1989@c * UNION and MAP::
1990* ENCODE and DECODE statements::
1991* Variable FORMAT expressions::
1992@c * Q edit descriptor::
1993@c * AUTOMATIC statement::
1994@c * TYPE and ACCEPT I/O Statements::
1995@c * .XOR. operator::
1996@c * CARRIAGECONTROL, DEFAULTFILE, DISPOSE and RECORDTYPE I/O specifiers::
1997@c * Omitted arguments in procedure call::
1998* Alternate complex function syntax::
1999@end menu
2000
2001
2002@node STRUCTURE and RECORD
2003@subsection @code{STRUCTURE} and @code{RECORD}
2004@cindex @code{STRUCTURE}
2005@cindex @code{RECORD}
2006
2007Record structures are a pre-Fortran-90 vendor extension to create
2008user-defined aggregate data types.  GNU Fortran does not support
2009record structures, only Fortran 90's ``derived types'', which have
2010a different syntax.
2011
2012In many cases, record structures can easily be converted to derived types.
2013To convert, replace @code{STRUCTURE /}@var{structure-name}@code{/}
2014by @code{TYPE} @var{type-name}.  Additionally, replace
2015@code{RECORD /}@var{structure-name}@code{/} by
2016@code{TYPE(}@var{type-name}@code{)}. Finally, in the component access,
2017replace the period (@code{.}) by the percent sign (@code{%}).
2018
2019Here is an example of code using the non portable record structure syntax:
2020
2021@example
2022! Declaring a structure named ``item'' and containing three fields:
2023! an integer ID, an description string and a floating-point price.
2024STRUCTURE /item/
2025  INTEGER id
2026  CHARACTER(LEN=200) description
2027  REAL price
2028END STRUCTURE
2029
2030! Define two variables, an single record of type ``item''
2031! named ``pear'', and an array of items named ``store_catalog''
2032RECORD /item/ pear, store_catalog(100)
2033
2034! We can directly access the fields of both variables
2035pear.id = 92316
2036pear.description = "juicy D'Anjou pear"
2037pear.price = 0.15
2038store_catalog(7).id = 7831
2039store_catalog(7).description = "milk bottle"
2040store_catalog(7).price = 1.2
2041
2042! We can also manipulate the whole structure
2043store_catalog(12) = pear
2044print *, store_catalog(12)
2045@end example
2046
2047@noindent
2048This code can easily be rewritten in the Fortran 90 syntax as following:
2049
2050@example
2051! ``STRUCTURE /name/ ... END STRUCTURE'' becomes
2052! ``TYPE name ... END TYPE''
2053TYPE item
2054  INTEGER id
2055  CHARACTER(LEN=200) description
2056  REAL price
2057END TYPE
2058
2059! ``RECORD /name/ variable'' becomes ``TYPE(name) variable''
2060TYPE(item) pear, store_catalog(100)
2061
2062! Instead of using a dot (.) to access fields of a record, the
2063! standard syntax uses a percent sign (%)
2064pear%id = 92316
2065pear%description = "juicy D'Anjou pear"
2066pear%price = 0.15
2067store_catalog(7)%id = 7831
2068store_catalog(7)%description = "milk bottle"
2069store_catalog(7)%price = 1.2
2070
2071! Assignments of a whole variable do not change
2072store_catalog(12) = pear
2073print *, store_catalog(12)
2074@end example
2075
2076
2077@c @node UNION and MAP
2078@c @subsection @code{UNION} and @code{MAP}
2079@c @cindex @code{UNION}
2080@c @cindex @code{MAP}
2081@c
2082@c For help writing this one, see
2083@c http://www.eng.umd.edu/~nsw/ench250/fortran1.htm#UNION and
2084@c http://www.tacc.utexas.edu/services/userguides/pgi/pgiws_ug/pgi32u06.htm
2085
2086
2087@node ENCODE and DECODE statements
2088@subsection @code{ENCODE} and @code{DECODE} statements
2089@cindex @code{ENCODE}
2090@cindex @code{DECODE}
2091
2092GNU Fortran does not support the @code{ENCODE} and @code{DECODE}
2093statements.  These statements are best replaced by @code{READ} and
2094@code{WRITE} statements involving internal files (@code{CHARACTER}
2095variables and arrays), which have been part of the Fortran standard since
2096Fortran 77.  For example, replace a code fragment like
2097
2098@smallexample
2099      INTEGER*1 LINE(80)
2100      REAL A, B, C
2101c     ... Code that sets LINE
2102      DECODE (80, 9000, LINE) A, B, C
2103 9000 FORMAT (1X, 3(F10.5))
2104@end smallexample
2105
2106@noindent
2107with the following:
2108
2109@smallexample
2110      CHARACTER(LEN=80) LINE
2111      REAL A, B, C
2112c     ... Code that sets LINE
2113      READ (UNIT=LINE, FMT=9000) A, B, C
2114 9000 FORMAT (1X, 3(F10.5))
2115@end smallexample
2116
2117Similarly, replace a code fragment like
2118
2119@smallexample
2120      INTEGER*1 LINE(80)
2121      REAL A, B, C
2122c     ... Code that sets A, B and C
2123      ENCODE (80, 9000, LINE) A, B, C
2124 9000 FORMAT (1X, 'OUTPUT IS ', 3(F10.5))
2125@end smallexample
2126
2127@noindent
2128with the following:
2129
2130@smallexample
2131      CHARACTER(LEN=80) LINE
2132      REAL A, B, C
2133c     ... Code that sets A, B and C
2134      WRITE (UNIT=LINE, FMT=9000) A, B, C
2135 9000 FORMAT (1X, 'OUTPUT IS ', 3(F10.5))
2136@end smallexample
2137
2138
2139@node Variable FORMAT expressions
2140@subsection Variable @code{FORMAT} expressions
2141@cindex @code{FORMAT}
2142
2143A variable @code{FORMAT} expression is format statement which includes
2144angle brackets enclosing a Fortran expression: @code{FORMAT(I<N>)}.  GNU
2145Fortran does not support this legacy extension.  The effect of variable
2146format expressions can be reproduced by using the more powerful (and
2147standard) combination of internal output and string formats.  For example,
2148replace a code fragment like this:
2149
2150@smallexample
2151      WRITE(6,20) INT1
2152 20   FORMAT(I<N+1>)
2153@end smallexample
2154
2155@noindent
2156with the following:
2157
2158@smallexample
2159c     Variable declaration
2160      CHARACTER(LEN=20) FMT
2161c
2162c     Other code here...
2163c
2164      WRITE(FMT,'("(I", I0, ")")') N+1
2165      WRITE(6,FMT) INT1
2166@end smallexample
2167
2168@noindent
2169or with:
2170
2171@smallexample
2172c     Variable declaration
2173      CHARACTER(LEN=20) FMT
2174c
2175c     Other code here...
2176c
2177      WRITE(FMT,*) N+1
2178      WRITE(6,"(I" // ADJUSTL(FMT) // ")") INT1
2179@end smallexample
2180
2181
2182@node Alternate complex function syntax
2183@subsection Alternate complex function syntax
2184@cindex Complex function
2185
2186Some Fortran compilers, including @command{g77}, let the user declare
2187complex functions with the syntax @code{COMPLEX FUNCTION name*16()}, as
2188well as @code{COMPLEX*16 FUNCTION name()}.  Both are non-standard, legacy
2189extensions.  @command{gfortran} accepts the latter form, which is more
2190common, but not the former.
2191
2192
2193
2194@c ---------------------------------------------------------------------
2195@c Mixed-Language Programming
2196@c ---------------------------------------------------------------------
2197
2198@node Mixed-Language Programming
2199@chapter Mixed-Language Programming
2200@cindex Interoperability
2201@cindex Mixed-language programming
2202
2203@menu
2204* Interoperability with C::
2205* GNU Fortran Compiler Directives::
2206* Non-Fortran Main Program::
2207@end menu
2208
2209This chapter is about mixed-language interoperability, but also applies
2210if one links Fortran code compiled by different compilers.  In most cases,
2211use of the C Binding features of the Fortran 2003 standard is sufficient,
2212and their use is highly recommended.
2213
2214
2215@node Interoperability with C
2216@section Interoperability with C
2217
2218@menu
2219* Intrinsic Types::
2220* Derived Types and struct::
2221* Interoperable Global Variables::
2222* Interoperable Subroutines and Functions::
2223* Working with Pointers::
2224* Further Interoperability of Fortran with C::
2225@end menu
2226
2227Since Fortran 2003 (ISO/IEC 1539-1:2004(E)) there is a
2228standardized way to generate procedure and derived-type
2229declarations and global variables which are interoperable with C
2230(ISO/IEC 9899:1999).  The @code{bind(C)} attribute has been added
2231to inform the compiler that a symbol shall be interoperable with C;
2232also, some constraints are added.  Note, however, that not
2233all C features have a Fortran equivalent or vice versa.  For instance,
2234neither C's unsigned integers nor C's functions with variable number
2235of arguments have an equivalent in Fortran.
2236
2237Note that array dimensions are reversely ordered in C and that arrays in
2238C always start with index 0 while in Fortran they start by default with
22391.  Thus, an array declaration @code{A(n,m)} in Fortran matches
2240@code{A[m][n]} in C and accessing the element @code{A(i,j)} matches
2241@code{A[j-1][i-1]}.  The element following @code{A(i,j)} (C: @code{A[j-1][i-1]};
2242assuming @math{i < n}) in memory is @code{A(i+1,j)} (C: @code{A[j-1][i]}).
2243
2244@node Intrinsic Types
2245@subsection Intrinsic Types
2246
2247In order to ensure that exactly the same variable type and kind is used
2248in C and Fortran, the named constants shall be used which are defined in the
2249@code{ISO_C_BINDING} intrinsic module.  That module contains named constants
2250for kind parameters and character named constants for the escape sequences
2251in C.  For a list of the constants, see @ref{ISO_C_BINDING}.
2252
2253@node Derived Types and struct
2254@subsection Derived Types and struct
2255
2256For compatibility of derived types with @code{struct}, one needs to use
2257the @code{BIND(C)} attribute in the type declaration.  For instance, the
2258following type declaration
2259
2260@smallexample
2261 USE ISO_C_BINDING
2262 TYPE, BIND(C) :: myType
2263   INTEGER(C_INT) :: i1, i2
2264   INTEGER(C_SIGNED_CHAR) :: i3
2265   REAL(C_DOUBLE) :: d1
2266   COMPLEX(C_FLOAT_COMPLEX) :: c1
2267   CHARACTER(KIND=C_CHAR) :: str(5)
2268 END TYPE
2269@end smallexample
2270
2271matches the following @code{struct} declaration in C
2272
2273@smallexample
2274 struct @{
2275   int i1, i2;
2276   /* Note: "char" might be signed or unsigned.  */
2277   signed char i3;
2278   double d1;
2279   float _Complex c1;
2280   char str[5];
2281 @} myType;
2282@end smallexample
2283
2284Derived types with the C binding attribute shall not have the @code{sequence}
2285attribute, type parameters, the @code{extends} attribute, nor type-bound
2286procedures.  Every component must be of interoperable type and kind and may not
2287have the @code{pointer} or @code{allocatable} attribute.  The names of the
2288components are irrelevant for interoperability.
2289
2290As there exist no direct Fortran equivalents, neither unions nor structs
2291with bit field or variable-length array members are interoperable.
2292
2293@node Interoperable Global Variables
2294@subsection Interoperable Global Variables
2295
2296Variables can be made accessible from C using the C binding attribute,
2297optionally together with specifying a binding name.  Those variables
2298have to be declared in the declaration part of a @code{MODULE},
2299be of interoperable type, and have neither the @code{pointer} nor
2300the @code{allocatable} attribute.
2301
2302@smallexample
2303  MODULE m
2304    USE myType_module
2305    USE ISO_C_BINDING
2306    integer(C_INT), bind(C, name="_MyProject_flags") :: global_flag
2307    type(myType), bind(C) :: tp
2308  END MODULE
2309@end smallexample
2310
2311Here, @code{_MyProject_flags} is the case-sensitive name of the variable
2312as seen from C programs while @code{global_flag} is the case-insensitive
2313name as seen from Fortran.  If no binding name is specified, as for
2314@var{tp}, the C binding name is the (lowercase) Fortran binding name.
2315If a binding name is specified, only a single variable may be after the
2316double colon.  Note of warning: You cannot use a global variable to
2317access @var{errno} of the C library as the C standard allows it to be
2318a macro.  Use the @code{IERRNO} intrinsic (GNU extension) instead.
2319
2320@node Interoperable Subroutines and Functions
2321@subsection Interoperable Subroutines and Functions
2322
2323Subroutines and functions have to have the @code{BIND(C)} attribute to
2324be compatible with C.  The dummy argument declaration is relatively
2325straightforward.  However, one needs to be careful because C uses
2326call-by-value by default while Fortran behaves usually similar to
2327call-by-reference.  Furthermore, strings and pointers are handled
2328differently.  Note that in Fortran 2003 and 2008 only explicit size
2329and assumed-size arrays are supported but not assumed-shape or
2330deferred-shape (i.e. allocatable or pointer) arrays.  However, those
2331are allowed since the Technical Specification 29113, see
2332@ref{Further Interoperability of Fortran with C}
2333
2334To pass a variable by value, use the @code{VALUE} attribute.
2335Thus, the following C prototype
2336
2337@smallexample
2338@code{int func(int i, int *j)}
2339@end smallexample
2340
2341matches the Fortran declaration
2342
2343@smallexample
2344  integer(c_int) function func(i,j)
2345    use iso_c_binding, only: c_int
2346    integer(c_int), VALUE :: i
2347    integer(c_int) :: j
2348@end smallexample
2349
2350Note that pointer arguments also frequently need the @code{VALUE} attribute,
2351see @ref{Working with Pointers}.
2352
2353Strings are handled quite differently in C and Fortran.  In C a string
2354is a @code{NUL}-terminated array of characters while in Fortran each string
2355has a length associated with it and is thus not terminated (by e.g.
2356@code{NUL}).  For example, if one wants to use the following C function,
2357
2358@smallexample
2359  #include <stdio.h>
2360  void print_C(char *string) /* equivalent: char string[]  */
2361  @{
2362     printf("%s\n", string);
2363  @}
2364@end smallexample
2365
2366to print ``Hello World'' from Fortran, one can call it using
2367
2368@smallexample
2369  use iso_c_binding, only: C_CHAR, C_NULL_CHAR
2370  interface
2371    subroutine print_c(string) bind(C, name="print_C")
2372      use iso_c_binding, only: c_char
2373      character(kind=c_char) :: string(*)
2374    end subroutine print_c
2375  end interface
2376  call print_c(C_CHAR_"Hello World"//C_NULL_CHAR)
2377@end smallexample
2378
2379As the example shows, one needs to ensure that the
2380string is @code{NUL} terminated.  Additionally, the dummy argument
2381@var{string} of @code{print_C} is a length-one assumed-size
2382array; using @code{character(len=*)} is not allowed.  The example
2383above uses @code{c_char_"Hello World"} to ensure the string
2384literal has the right type; typically the default character
2385kind and @code{c_char} are the same and thus @code{"Hello World"}
2386is equivalent.  However, the standard does not guarantee this.
2387
2388The use of strings is now further illustrated using the C library
2389function @code{strncpy}, whose prototype is
2390
2391@smallexample
2392  char *strncpy(char *restrict s1, const char *restrict s2, size_t n);
2393@end smallexample
2394
2395The function @code{strncpy} copies at most @var{n} characters from
2396string @var{s2} to @var{s1} and returns @var{s1}.  In the following
2397example, we ignore the return value:
2398
2399@smallexample
2400  use iso_c_binding
2401  implicit none
2402  character(len=30) :: str,str2
2403  interface
2404    ! Ignore the return value of strncpy -> subroutine
2405    ! "restrict" is always assumed if we do not pass a pointer
2406    subroutine strncpy(dest, src, n) bind(C)
2407      import
2408      character(kind=c_char),  intent(out) :: dest(*)
2409      character(kind=c_char),  intent(in)  :: src(*)
2410      integer(c_size_t), value, intent(in) :: n
2411    end subroutine strncpy
2412  end interface
2413  str = repeat('X',30) ! Initialize whole string with 'X'
2414  call strncpy(str, c_char_"Hello World"//C_NULL_CHAR, &
2415               len(c_char_"Hello World",kind=c_size_t))
2416  print '(a)', str ! prints: "Hello WorldXXXXXXXXXXXXXXXXXXX"
2417  end
2418@end smallexample
2419
2420The intrinsic procedures are described in @ref{Intrinsic Procedures}.
2421
2422@node Working with Pointers
2423@subsection Working with Pointers
2424
2425C pointers are represented in Fortran via the special opaque derived type
2426@code{type(c_ptr)} (with private components).  Thus one needs to
2427use intrinsic conversion procedures to convert from or to C pointers.
2428
2429For some applications, using an assumed type (@code{TYPE(*)}) can be an
2430alternative to a C pointer; see
2431@ref{Further Interoperability of Fortran with C}.
2432
2433For example,
2434
2435@smallexample
2436  use iso_c_binding
2437  type(c_ptr) :: cptr1, cptr2
2438  integer, target :: array(7), scalar
2439  integer, pointer :: pa(:), ps
2440  cptr1 = c_loc(array(1)) ! The programmer needs to ensure that the
2441                          ! array is contiguous if required by the C
2442                          ! procedure
2443  cptr2 = c_loc(scalar)
2444  call c_f_pointer(cptr2, ps)
2445  call c_f_pointer(cptr2, pa, shape=[7])
2446@end smallexample
2447
2448When converting C to Fortran arrays, the one-dimensional @code{SHAPE} argument
2449has to be passed.
2450
2451If a pointer is a dummy-argument of an interoperable procedure, it usually
2452has to be declared using the @code{VALUE} attribute.  @code{void*}
2453matches @code{TYPE(C_PTR), VALUE}, while @code{TYPE(C_PTR)} alone
2454matches @code{void**}.
2455
2456Procedure pointers are handled analogously to pointers; the C type is
2457@code{TYPE(C_FUNPTR)} and the intrinsic conversion procedures are
2458@code{C_F_PROCPOINTER} and @code{C_FUNLOC}.
2459
2460Let us consider two examples of actually passing a procedure pointer from
2461C to Fortran and vice versa.  Note that these examples are also very
2462similar to passing ordinary pointers between both languages. First,
2463consider this code in C:
2464
2465@smallexample
2466/* Procedure implemented in Fortran.  */
2467void get_values (void (*)(double));
2468
2469/* Call-back routine we want called from Fortran.  */
2470void
2471print_it (double x)
2472@{
2473  printf ("Number is %f.\n", x);
2474@}
2475
2476/* Call Fortran routine and pass call-back to it.  */
2477void
2478foobar ()
2479@{
2480  get_values (&print_it);
2481@}
2482@end smallexample
2483
2484A matching implementation for @code{get_values} in Fortran, that correctly
2485receives the procedure pointer from C and is able to call it, is given
2486in the following @code{MODULE}:
2487
2488@smallexample
2489MODULE m
2490  IMPLICIT NONE
2491
2492  ! Define interface of call-back routine.
2493  ABSTRACT INTERFACE
2494    SUBROUTINE callback (x)
2495      USE, INTRINSIC :: ISO_C_BINDING
2496      REAL(KIND=C_DOUBLE), INTENT(IN), VALUE :: x
2497    END SUBROUTINE callback
2498  END INTERFACE
2499
2500CONTAINS
2501
2502  ! Define C-bound procedure.
2503  SUBROUTINE get_values (cproc) BIND(C)
2504    USE, INTRINSIC :: ISO_C_BINDING
2505    TYPE(C_FUNPTR), INTENT(IN), VALUE :: cproc
2506
2507    PROCEDURE(callback), POINTER :: proc
2508
2509    ! Convert C to Fortran procedure pointer.
2510    CALL C_F_PROCPOINTER (cproc, proc)
2511
2512    ! Call it.
2513    CALL proc (1.0_C_DOUBLE)
2514    CALL proc (-42.0_C_DOUBLE)
2515    CALL proc (18.12_C_DOUBLE)
2516  END SUBROUTINE get_values
2517
2518END MODULE m
2519@end smallexample
2520
2521Next, we want to call a C routine that expects a procedure pointer argument
2522and pass it a Fortran procedure (which clearly must be interoperable!).
2523Again, the C function may be:
2524
2525@smallexample
2526int
2527call_it (int (*func)(int), int arg)
2528@{
2529  return func (arg);
2530@}
2531@end smallexample
2532
2533It can be used as in the following Fortran code:
2534
2535@smallexample
2536MODULE m
2537  USE, INTRINSIC :: ISO_C_BINDING
2538  IMPLICIT NONE
2539
2540  ! Define interface of C function.
2541  INTERFACE
2542    INTEGER(KIND=C_INT) FUNCTION call_it (func, arg) BIND(C)
2543      USE, INTRINSIC :: ISO_C_BINDING
2544      TYPE(C_FUNPTR), INTENT(IN), VALUE :: func
2545      INTEGER(KIND=C_INT), INTENT(IN), VALUE :: arg
2546    END FUNCTION call_it
2547  END INTERFACE
2548
2549CONTAINS
2550
2551  ! Define procedure passed to C function.
2552  ! It must be interoperable!
2553  INTEGER(KIND=C_INT) FUNCTION double_it (arg) BIND(C)
2554    INTEGER(KIND=C_INT), INTENT(IN), VALUE :: arg
2555    double_it = arg + arg
2556  END FUNCTION double_it
2557
2558  ! Call C function.
2559  SUBROUTINE foobar ()
2560    TYPE(C_FUNPTR) :: cproc
2561    INTEGER(KIND=C_INT) :: i
2562
2563    ! Get C procedure pointer.
2564    cproc = C_FUNLOC (double_it)
2565
2566    ! Use it.
2567    DO i = 1_C_INT, 10_C_INT
2568      PRINT *, call_it (cproc, i)
2569    END DO
2570  END SUBROUTINE foobar
2571
2572END MODULE m
2573@end smallexample
2574
2575@node Further Interoperability of Fortran with C
2576@subsection Further Interoperability of Fortran with C
2577
2578The Technical Specification ISO/IEC TS 29113:2012 on further
2579interoperability of Fortran with C extends the interoperability support
2580of Fortran 2003 and Fortran 2008. Besides removing some restrictions
2581and constraints, it adds assumed-type (@code{TYPE(*)}) and assumed-rank
2582(@code{dimension}) variables and allows for interoperability of
2583assumed-shape, assumed-rank and deferred-shape arrays, including
2584allocatables and pointers.
2585
2586Note: Currently, GNU Fortran does not support the array descriptor
2587(dope vector) as specified in the Technical Specification, but uses
2588an array descriptor with different fields. The Chasm Language
2589Interoperability Tools, @url{http://chasm-interop.sourceforge.net/},
2590provide an interface to GNU Fortran's array descriptor.
2591
2592The Technical Specification adds the following new features, which
2593are supported by GNU Fortran:
2594
2595@itemize @bullet
2596
2597@item The @code{ASYNCHRONOUS} attribute has been clarified and
2598extended to allow its use with asynchronous communication in
2599user-provided libraries such as in implementations of the
2600Message Passing Interface specification.
2601
2602@item Many constraints have been relaxed, in particular for
2603the @code{C_LOC} and @code{C_F_POINTER} intrinsics.
2604
2605@item The @code{OPTIONAL} attribute is now allowed for dummy
2606arguments; an absent argument matches a @code{NULL} pointer.
2607
2608@item Assumed types (@code{TYPE(*)}) have been added, which may
2609only be used for dummy arguments.  They are unlimited polymorphic
2610but contrary to @code{CLASS(*)} they do not contain any type
2611information, similar to C's @code{void *} pointers.  Expressions
2612of any type and kind can be passed; thus, it can be used as
2613replacement for @code{TYPE(C_PTR)}, avoiding the use of
2614@code{C_LOC} in the caller.
2615
2616Note, however, that @code{TYPE(*)} only accepts scalar arguments,
2617unless the @code{DIMENSION} is explicitly specified.  As
2618@code{DIMENSION(*)} only supports array (including array elements) but
2619no scalars, it is not a full replacement for @code{C_LOC}.  On the
2620other hand, assumed-type assumed-rank dummy arguments
2621(@code{TYPE(*), DIMENSION(..)}) allow for both scalars and arrays, but
2622require special code on the callee side to handle the array descriptor.
2623
2624@item Assumed-shape arrays (@code{DIMENSION(..)}) as dummy argument
2625allow that scalars and arrays of any rank can be passed as actual
2626argument. As the Technical Specification does not provide for direct
2627means to operate with them, they have to be used either from the C side
2628or be converted using @code{C_LOC} and @code{C_F_POINTER} to scalars
2629or arrays of a specific rank. The rank can be determined using the
2630@code{RANK} intrinisic.
2631@end itemize
2632
2633
2634Currently unimplemented:
2635
2636@itemize @bullet
2637
2638@item GNU Fortran always uses an array descriptor, which does not
2639match the one of the Technical Specification. The
2640@code{ISO_Fortran_binding.h} header file and the C functions it
2641specifies are not available.
2642
2643@item Using assumed-shape, assumed-rank and deferred-shape arrays in
2644@code{BIND(C)} procedures is not fully supported. In particular,
2645C interoperable strings of other length than one are not supported
2646as this requires the new array descriptor.
2647@end itemize
2648
2649
2650@node GNU Fortran Compiler Directives
2651@section GNU Fortran Compiler Directives
2652
2653The Fortran standard describes how a conforming program shall
2654behave; however, the exact implementation is not standardized.  In order
2655to allow the user to choose specific implementation details, compiler
2656directives can be used to set attributes of variables and procedures
2657which are not part of the standard.  Whether a given attribute is
2658supported and its exact effects depend on both the operating system and
2659on the processor; see
2660@ref{Top,,C Extensions,gcc,Using the GNU Compiler Collection (GCC)}
2661for details.
2662
2663For procedures and procedure pointers, the following attributes can
2664be used to change the calling convention:
2665
2666@itemize
2667@item @code{CDECL} -- standard C calling convention
2668@item @code{STDCALL} -- convention where the called procedure pops the stack
2669@item @code{FASTCALL} -- part of the arguments are passed via registers
2670instead using the stack
2671@end itemize
2672
2673Besides changing the calling convention, the attributes also influence
2674the decoration of the symbol name, e.g., by a leading underscore or by
2675a trailing at-sign followed by the number of bytes on the stack.  When
2676assigning a procedure to a procedure pointer, both should use the same
2677calling convention.
2678
2679On some systems, procedures and global variables (module variables and
2680@code{COMMON} blocks) need special handling to be accessible when they
2681are in a shared library.  The following attributes are available:
2682
2683@itemize
2684@item @code{DLLEXPORT} -- provide a global pointer to a pointer in the DLL
2685@item @code{DLLIMPORT} -- reference the function or variable using a global pointer
2686@end itemize
2687
2688The attributes are specified using the syntax
2689
2690@code{!GCC$ ATTRIBUTES} @var{attribute-list} @code{::} @var{variable-list}
2691
2692where in free-form source code only whitespace is allowed before @code{!GCC$}
2693and in fixed-form source code @code{!GCC$}, @code{cGCC$} or @code{*GCC$} shall
2694start in the first column.
2695
2696For procedures, the compiler directives shall be placed into the body
2697of the procedure; for variables and procedure pointers, they shall be in
2698the same declaration part as the variable or procedure pointer.
2699
2700
2701
2702@node Non-Fortran Main Program
2703@section Non-Fortran Main Program
2704
2705@menu
2706* _gfortran_set_args:: Save command-line arguments
2707* _gfortran_set_options:: Set library option flags
2708* _gfortran_set_convert:: Set endian conversion
2709* _gfortran_set_record_marker:: Set length of record markers
2710* _gfortran_set_fpe:: Set when a Floating Point Exception should be raised
2711* _gfortran_set_max_subrecord_length:: Set subrecord length
2712@end menu
2713
2714Even if you are doing mixed-language programming, it is very
2715likely that you do not need to know or use the information in this
2716section.  Since it is about the internal structure of GNU Fortran,
2717it may also change in GCC minor releases.
2718
2719When you compile a @code{PROGRAM} with GNU Fortran, a function
2720with the name @code{main} (in the symbol table of the object file)
2721is generated, which initializes the libgfortran library and then
2722calls the actual program which uses the name @code{MAIN__}, for
2723historic reasons.  If you link GNU Fortran compiled procedures
2724to, e.g., a C or C++ program or to a Fortran program compiled by
2725a different compiler, the libgfortran library is not initialized
2726and thus a few intrinsic procedures do not work properly, e.g.
2727those for obtaining the command-line arguments.
2728
2729Therefore, if your @code{PROGRAM} is not compiled with
2730GNU Fortran and the GNU Fortran compiled procedures require
2731intrinsics relying on the library initialization, you need to
2732initialize the library yourself.  Using the default options,
2733gfortran calls @code{_gfortran_set_args} and
2734@code{_gfortran_set_options}.  The initialization of the former
2735is needed if the called procedures access the command line
2736(and for backtracing); the latter sets some flags based on the
2737standard chosen or to enable backtracing.  In typical programs,
2738it is not necessary to call any initialization function.
2739
2740If your @code{PROGRAM} is compiled with GNU Fortran, you shall
2741not call any of the following functions.  The libgfortran
2742initialization functions are shown in C syntax but using C
2743bindings they are also accessible from Fortran.
2744
2745
2746@node _gfortran_set_args
2747@subsection @code{_gfortran_set_args} --- Save command-line arguments
2748@fnindex _gfortran_set_args
2749@cindex libgfortran initialization, set_args
2750
2751@table @asis
2752@item @emph{Description}:
2753@code{_gfortran_set_args} saves the command-line arguments; this
2754initialization is required if any of the command-line intrinsics
2755is called.  Additionally, it shall be called if backtracing is
2756enabled (see @code{_gfortran_set_options}).
2757
2758@item @emph{Syntax}:
2759@code{void _gfortran_set_args (int argc, char *argv[])}
2760
2761@item @emph{Arguments}:
2762@multitable @columnfractions .15 .70
2763@item @var{argc} @tab number of command line argument strings
2764@item @var{argv} @tab the command-line argument strings; argv[0]
2765is the pathname of the executable itself.
2766@end multitable
2767
2768@item @emph{Example}:
2769@smallexample
2770int main (int argc, char *argv[])
2771@{
2772  /* Initialize libgfortran.  */
2773  _gfortran_set_args (argc, argv);
2774  return 0;
2775@}
2776@end smallexample
2777@end table
2778
2779
2780@node _gfortran_set_options
2781@subsection @code{_gfortran_set_options} --- Set library option flags
2782@fnindex _gfortran_set_options
2783@cindex libgfortran initialization, set_options
2784
2785@table @asis
2786@item @emph{Description}:
2787@code{_gfortran_set_options} sets several flags related to the Fortran
2788standard to be used, whether backtracing should be enabled
2789and whether range checks should be performed.  The syntax allows for
2790upward compatibility since the number of passed flags is specified; for
2791non-passed flags, the default value is used.  See also
2792@pxref{Code Gen Options}.  Please note that not all flags are actually
2793used.
2794
2795@item @emph{Syntax}:
2796@code{void _gfortran_set_options (int num, int options[])}
2797
2798@item @emph{Arguments}:
2799@multitable @columnfractions .15 .70
2800@item @var{num} @tab number of options passed
2801@item @var{argv} @tab The list of flag values
2802@end multitable
2803
2804@item @emph{option flag list}:
2805@multitable @columnfractions .15 .70
2806@item @var{option}[0] @tab Allowed standard; can give run-time errors
2807if e.g. an input-output edit descriptor is invalid in a given standard.
2808Possible values are (bitwise or-ed) @code{GFC_STD_F77} (1),
2809@code{GFC_STD_F95_OBS} (2), @code{GFC_STD_F95_DEL} (4), @code{GFC_STD_F95}
2810(8), @code{GFC_STD_F2003} (16), @code{GFC_STD_GNU} (32),
2811@code{GFC_STD_LEGACY} (64), @code{GFC_STD_F2008} (128),
2812@code{GFC_STD_F2008_OBS} (256) and GFC_STD_F2008_TS (512). Default:
2813@code{GFC_STD_F95_OBS | GFC_STD_F95_DEL | GFC_STD_F95 | GFC_STD_F2003
2814| GFC_STD_F2008 | GFC_STD_F2008_TS | GFC_STD_F2008_OBS | GFC_STD_F77
2815| GFC_STD_GNU | GFC_STD_LEGACY}.
2816@item @var{option}[1] @tab Standard-warning flag; prints a warning to
2817standard error.  Default: @code{GFC_STD_F95_DEL | GFC_STD_LEGACY}.
2818@item @var{option}[2] @tab If non zero, enable pedantic checking.
2819Default: off.
2820@item @var{option}[3] @tab Unused.
2821@item @var{option}[4] @tab If non zero, enable backtracing on run-time
2822errors.  Default: off.
2823Note: Installs a signal handler and requires command-line
2824initialization using @code{_gfortran_set_args}.
2825@item @var{option}[5] @tab If non zero, supports signed zeros.
2826Default: enabled.
2827@item @var{option}[6] @tab Enables run-time checking.  Possible values
2828are (bitwise or-ed): GFC_RTCHECK_BOUNDS (1), GFC_RTCHECK_ARRAY_TEMPS (2),
2829GFC_RTCHECK_RECURSION (4), GFC_RTCHECK_DO (16), GFC_RTCHECK_POINTER (32).
2830Default: disabled.
2831@end multitable
2832
2833@item @emph{Example}:
2834@smallexample
2835  /* Use gfortran 4.8 default options.  */
2836  static int options[] = @{68, 511, 0, 0, 1, 1, 0@};
2837  _gfortran_set_options (7, &options);
2838@end smallexample
2839@end table
2840
2841
2842@node _gfortran_set_convert
2843@subsection @code{_gfortran_set_convert} --- Set endian conversion
2844@fnindex _gfortran_set_convert
2845@cindex libgfortran initialization, set_convert
2846
2847@table @asis
2848@item @emph{Description}:
2849@code{_gfortran_set_convert} set the representation of data for
2850unformatted files.
2851
2852@item @emph{Syntax}:
2853@code{void _gfortran_set_convert (int conv)}
2854
2855@item @emph{Arguments}:
2856@multitable @columnfractions .15 .70
2857@item @var{conv} @tab Endian conversion, possible values:
2858GFC_CONVERT_NATIVE (0, default), GFC_CONVERT_SWAP (1),
2859GFC_CONVERT_BIG (2), GFC_CONVERT_LITTLE (3).
2860@end multitable
2861
2862@item @emph{Example}:
2863@smallexample
2864int main (int argc, char *argv[])
2865@{
2866  /* Initialize libgfortran.  */
2867  _gfortran_set_args (argc, argv);
2868  _gfortran_set_convert (1);
2869  return 0;
2870@}
2871@end smallexample
2872@end table
2873
2874
2875@node _gfortran_set_record_marker
2876@subsection @code{_gfortran_set_record_marker} --- Set length of record markers
2877@fnindex _gfortran_set_record_marker
2878@cindex libgfortran initialization, set_record_marker
2879
2880@table @asis
2881@item @emph{Description}:
2882@code{_gfortran_set_record_marker} sets the length of record markers
2883for unformatted files.
2884
2885@item @emph{Syntax}:
2886@code{void _gfortran_set_record_marker (int val)}
2887
2888@item @emph{Arguments}:
2889@multitable @columnfractions .15 .70
2890@item @var{val} @tab Length of the record marker; valid values
2891are 4 and 8.  Default is 4.
2892@end multitable
2893
2894@item @emph{Example}:
2895@smallexample
2896int main (int argc, char *argv[])
2897@{
2898  /* Initialize libgfortran.  */
2899  _gfortran_set_args (argc, argv);
2900  _gfortran_set_record_marker (8);
2901  return 0;
2902@}
2903@end smallexample
2904@end table
2905
2906
2907@node _gfortran_set_fpe
2908@subsection @code{_gfortran_set_fpe} --- Enable floating point exception traps
2909@fnindex _gfortran_set_fpe
2910@cindex libgfortran initialization, set_fpe
2911
2912@table @asis
2913@item @emph{Description}:
2914@code{_gfortran_set_fpe} enables floating point exception traps for
2915the specified exceptions.  On most systems, this will result in a
2916SIGFPE signal being sent and the program being aborted.
2917
2918@item @emph{Syntax}:
2919@code{void _gfortran_set_fpe (int val)}
2920
2921@item @emph{Arguments}:
2922@multitable @columnfractions .15 .70
2923@item @var{option}[0] @tab IEEE exceptions.  Possible values are
2924(bitwise or-ed) zero (0, default) no trapping,
2925@code{GFC_FPE_INVALID} (1), @code{GFC_FPE_DENORMAL} (2),
2926@code{GFC_FPE_ZERO} (4), @code{GFC_FPE_OVERFLOW} (8),
2927@code{GFC_FPE_UNDERFLOW} (16), and @code{GFC_FPE_INEXACT} (32).
2928@end multitable
2929
2930@item @emph{Example}:
2931@smallexample
2932int main (int argc, char *argv[])
2933@{
2934  /* Initialize libgfortran.  */
2935  _gfortran_set_args (argc, argv);
2936  /* FPE for invalid operations such as SQRT(-1.0).  */
2937  _gfortran_set_fpe (1);
2938  return 0;
2939@}
2940@end smallexample
2941@end table
2942
2943
2944@node _gfortran_set_max_subrecord_length
2945@subsection @code{_gfortran_set_max_subrecord_length} --- Set subrecord length
2946@fnindex _gfortran_set_max_subrecord_length
2947@cindex libgfortran initialization, set_max_subrecord_length
2948
2949@table @asis
2950@item @emph{Description}:
2951@code{_gfortran_set_max_subrecord_length} set the maximum length
2952for a subrecord.  This option only makes sense for testing and
2953debugging of unformatted I/O.
2954
2955@item @emph{Syntax}:
2956@code{void _gfortran_set_max_subrecord_length (int val)}
2957
2958@item @emph{Arguments}:
2959@multitable @columnfractions .15 .70
2960@item @var{val} @tab the maximum length for a subrecord;
2961the maximum permitted value is 2147483639, which is also
2962the default.
2963@end multitable
2964
2965@item @emph{Example}:
2966@smallexample
2967int main (int argc, char *argv[])
2968@{
2969  /* Initialize libgfortran.  */
2970  _gfortran_set_args (argc, argv);
2971  _gfortran_set_max_subrecord_length (8);
2972  return 0;
2973@}
2974@end smallexample
2975@end table
2976
2977
2978
2979@c Intrinsic Procedures
2980@c ---------------------------------------------------------------------
2981
2982@include intrinsic.texi
2983
2984
2985@tex
2986\blankpart
2987@end tex
2988
2989@c ---------------------------------------------------------------------
2990@c Contributing
2991@c ---------------------------------------------------------------------
2992
2993@node Contributing
2994@unnumbered Contributing
2995@cindex Contributing
2996
2997Free software is only possible if people contribute to efforts
2998to create it.
2999We're always in need of more people helping out with ideas
3000and comments, writing documentation and contributing code.
3001
3002If you want to contribute to GNU Fortran,
3003have a look at the long lists of projects you can take on.
3004Some of these projects are small,
3005some of them are large;
3006some are completely orthogonal to the rest of what is
3007happening on GNU Fortran,
3008but others are ``mainstream'' projects in need of enthusiastic hackers.
3009All of these projects are important!
3010We will eventually get around to the things here,
3011but they are also things doable by someone who is willing and able.
3012
3013@menu
3014* Contributors::
3015* Projects::
3016* Proposed Extensions::
3017@end menu
3018
3019
3020@node Contributors
3021@section Contributors to GNU Fortran
3022@cindex Contributors
3023@cindex Credits
3024@cindex Authors
3025
3026Most of the parser was hand-crafted by @emph{Andy Vaught}, who is
3027also the initiator of the whole project.  Thanks Andy!
3028Most of the interface with GCC was written by @emph{Paul Brook}.
3029
3030The following individuals have contributed code and/or
3031ideas and significant help to the GNU Fortran project
3032(in alphabetical order):
3033
3034@itemize @minus
3035@item Janne Blomqvist
3036@item Steven Bosscher
3037@item Paul Brook
3038@item Tobias Burnus
3039@item Fran@,{c}ois-Xavier Coudert
3040@item Bud Davis
3041@item Jerry DeLisle
3042@item Erik Edelmann
3043@item Bernhard Fischer
3044@item Daniel Franke
3045@item Richard Guenther
3046@item Richard Henderson
3047@item Katherine Holcomb
3048@item Jakub Jelinek
3049@item Niels Kristian Bech Jensen
3050@item Steven Johnson
3051@item Steven G. Kargl
3052@item Thomas Koenig
3053@item Asher Langton
3054@item H. J. Lu
3055@item Toon Moene
3056@item Brooks Moses
3057@item Andrew Pinski
3058@item Tim Prince
3059@item Christopher D. Rickett
3060@item Richard Sandiford
3061@item Tobias Schl@"uter
3062@item Roger Sayle
3063@item Paul Thomas
3064@item Andy Vaught
3065@item Feng Wang
3066@item Janus Weil
3067@item Daniel Kraft
3068@end itemize
3069
3070The following people have contributed bug reports,
3071smaller or larger patches,
3072and much needed feedback and encouragement for the
3073GNU Fortran project:
3074
3075@itemize @minus
3076@item Bill Clodius
3077@item Dominique d'Humi@`eres
3078@item Kate Hedstrom
3079@item Erik Schnetter
3080@item Joost VandeVondele
3081@end itemize
3082
3083Many other individuals have helped debug,
3084test and improve the GNU Fortran compiler over the past few years,
3085and we welcome you to do the same!
3086If you already have done so,
3087and you would like to see your name listed in the
3088list above, please contact us.
3089
3090
3091@node Projects
3092@section Projects
3093
3094@table @emph
3095
3096@item Help build the test suite
3097Solicit more code for donation to the test suite: the more extensive the
3098testsuite, the smaller the risk of breaking things in the future! We can
3099keep code private on request.
3100
3101@item Bug hunting/squishing
3102Find bugs and write more test cases! Test cases are especially very
3103welcome, because it allows us to concentrate on fixing bugs instead of
3104isolating them.  Going through the bugzilla database at
3105@url{http://gcc.gnu.org/@/bugzilla/} to reduce testcases posted there and
3106add more information (for example, for which version does the testcase
3107work, for which versions does it fail?) is also very helpful.
3108
3109@end table
3110
3111
3112@node Proposed Extensions
3113@section Proposed Extensions
3114
3115Here's a list of proposed extensions for the GNU Fortran compiler, in no particular
3116order.  Most of these are necessary to be fully compatible with
3117existing Fortran compilers, but they are not part of the official
3118J3 Fortran 95 standard.
3119
3120@subsection Compiler extensions:
3121@itemize @bullet
3122@item
3123User-specified alignment rules for structures.
3124
3125@item
3126Automatically extend single precision constants to double.
3127
3128@item
3129Compile code that conserves memory by dynamically allocating common and
3130module storage either on stack or heap.
3131
3132@item
3133Compile flag to generate code for array conformance checking (suggest -CC).
3134
3135@item
3136User control of symbol names (underscores, etc).
3137
3138@item
3139Compile setting for maximum size of stack frame size before spilling
3140parts to static or heap.
3141
3142@item
3143Flag to force local variables into static space.
3144
3145@item
3146Flag to force local variables onto stack.
3147@end itemize
3148
3149
3150@subsection Environment Options
3151@itemize @bullet
3152@item
3153Pluggable library modules for random numbers, linear algebra.
3154LA should use BLAS calling conventions.
3155
3156@item
3157Environment variables controlling actions on arithmetic exceptions like
3158overflow, underflow, precision loss---Generate NaN, abort, default.
3159action.
3160
3161@item
3162Set precision for fp units that support it (i387).
3163
3164@item
3165Variable for setting fp rounding mode.
3166
3167@item
3168Variable to fill uninitialized variables with a user-defined bit
3169pattern.
3170
3171@item
3172Environment variable controlling filename that is opened for that unit
3173number.
3174
3175@item
3176Environment variable to clear/trash memory being freed.
3177
3178@item
3179Environment variable to control tracing of allocations and frees.
3180
3181@item
3182Environment variable to display allocated memory at normal program end.
3183
3184@item
3185Environment variable for filename for * IO-unit.
3186
3187@item
3188Environment variable for temporary file directory.
3189
3190@item
3191Environment variable forcing standard output to be line buffered (Unix).
3192
3193@end itemize
3194
3195
3196@c ---------------------------------------------------------------------
3197@c GNU General Public License
3198@c ---------------------------------------------------------------------
3199
3200@include gpl_v3.texi
3201
3202
3203
3204@c ---------------------------------------------------------------------
3205@c GNU Free Documentation License
3206@c ---------------------------------------------------------------------
3207
3208@include fdl.texi
3209
3210
3211
3212@c ---------------------------------------------------------------------
3213@c Funding Free Software
3214@c ---------------------------------------------------------------------
3215
3216@include funding.texi
3217
3218@c ---------------------------------------------------------------------
3219@c Indices
3220@c ---------------------------------------------------------------------
3221
3222@node Option Index
3223@unnumbered Option Index
3224@command{gfortran}'s command line options are indexed here without any
3225initial @samp{-} or @samp{--}.  Where an option has both positive and
3226negative forms (such as -foption and -fno-option), relevant entries in
3227the manual are indexed under the most appropriate form; it may sometimes
3228be useful to look up both forms.
3229@printindex op
3230
3231@node Keyword Index
3232@unnumbered Keyword Index
3233@printindex cp
3234
3235@bye
3236