]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/fortran/gfortran.texi
combine.c: Include cgraph.h.
[thirdparty/gcc.git] / gcc / fortran / gfortran.texi
CommitLineData
6de9cd9a
DN
1\input texinfo @c -*-texinfo-*-
2@c %**start of header
3@setfilename gfortran.info
2553e4e0 4@set copyrights-gfortran 1999-2007
6de9cd9a
DN
5
6@include gcc-common.texi
7
7fc15ba5 8@settitle The GNU Fortran Compiler
6de9cd9a
DN
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
c8cf50e4
BM
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
6de9cd9a
DN
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.1 or
84any later version published by the Free Software Foundation; with the
85Invariant Sections being ``GNU General Public License'' and ``Funding
86Free Software'', the Front-Cover
87texts being (a) (see below), and with the Back-Cover Texts being (b)
88(see below). A copy of the license is included in the section entitled
89``GNU Free Documentation License''.
90
91(a) The FSF's Front-Cover Text is:
92
93 A GNU Manual
94
95(b) The FSF's Back-Cover Text is:
96
97 You have freedom to copy and modify this GNU Manual, like GNU
98 software. Copies published by the Free Software Foundation raise
99 funds for GNU development.
100@end copying
101
102@ifinfo
2cec61bd 103@dircategory Software development
6de9cd9a 104@direntry
7fc15ba5 105* gfortran: (gfortran). The GNU Fortran Compiler.
6de9cd9a
DN
106@end direntry
107This file documents the use and the internals of
7fc15ba5 108the GNU Fortran compiler, (@command{gfortran}).
6de9cd9a
DN
109
110Published by the Free Software Foundation
ab57747b
KC
11151 Franklin Street, Fifth Floor
112Boston, MA 02110-1301 USA
6de9cd9a
DN
113
114@insertcopying
115@end ifinfo
116
6de9cd9a
DN
117
118@setchapternewpage odd
119@titlepage
7fc15ba5 120@title Using GNU Fortran
7771bb62
BM
121@versionsubtitle
122@author The @t{gfortran} team
6de9cd9a
DN
123@page
124@vskip 0pt plus 1filll
4e8b3590 125Published by the Free Software Foundation@*
ab57747b
KC
12651 Franklin Street, Fifth Floor@*
127Boston, MA 02110-1301, USA@*
6de9cd9a
DN
128@c Last printed ??ber, 19??.@*
129@c Printed copies are available for $? each.@*
130@c ISBN ???
131@sp 1
132@insertcopying
133@end titlepage
c8cf50e4
BM
134
135@c TODO: The following "Part" definitions are included here temporarily
136@c until they are incorporated into the official Texinfo distribution.
137
138@tex
139\global\let\partentry=\dosmallpartentry
140\global\let\blankpartentry=\dosmallblankpartentry
141@end tex
6de9cd9a 142@summarycontents
c8cf50e4
BM
143
144@tex
145\global\let\partentry=\dopartentry
146\global\let\blankpartentry=\doblankpartentry
147@end tex
6de9cd9a 148@contents
c8cf50e4 149
6de9cd9a
DN
150@page
151
e6b38f67
BM
152@c ---------------------------------------------------------------------
153@c TexInfo table of contents.
154@c ---------------------------------------------------------------------
155
156@ifnottex
a63dad5b 157@node Top
6de9cd9a
DN
158@top Introduction
159@cindex Introduction
160
161This manual documents the use of @command{gfortran},
7fc15ba5 162the GNU Fortran compiler. You can find in this manual how to invoke
e0f2a7c6 163@command{gfortran}, as well as its features and incompatibilities.
6de9cd9a
DN
164
165@ifset DEVELOPMENT
166@emph{Warning:} This document, and the compiler it describes, are still
8db2ba40 167under development. While efforts are made to keep it up-to-date, it might
7fc15ba5 168not accurately reflect the status of the most recent GNU Fortran compiler.
6de9cd9a
DN
169@end ifset
170
8db2ba40
SK
171@comment
172@comment When you add a new menu item, please keep the right hand
173@comment aligned to the same column. Do not use tabs. This provides
174@comment better formatting.
175@comment
6de9cd9a 176@menu
e6b38f67 177* Introduction::
c8cf50e4 178
e6b38f67 179Part I: Invoking GNU Fortran
c8cf50e4 180* Invoking GNU Fortran:: Command options supported by @command{gfortran}.
eaa90d25 181* Runtime:: Influencing runtime behavior with environment variables.
c8cf50e4 182
e6b38f67 183Part II: Language Reference
c8cf50e4 184* Fortran 2003 status:: Fortran 2003 features supported by GNU Fortran.
7fc15ba5
BM
185* Extensions:: Language extensions implemented by GNU Fortran.
186* Intrinsic Procedures:: Intrinsic procedures supported by GNU Fortran.
c8cf50e4
BM
187
188* Contributing:: How you can help.
a63dad5b
TS
189* Copying:: GNU General Public License says
190 how you can copy and share GNU Fortran.
191* GNU Free Documentation License::
192 How you can copy and share this manual.
193* Funding:: How to help assure continued work for free software.
32864778
DF
194* Option Index:: Index of command line options
195* Keyword Index:: Index of concepts
6de9cd9a 196@end menu
e6b38f67 197@end ifnottex
6de9cd9a 198
6de9cd9a 199@c ---------------------------------------------------------------------
e6b38f67 200@c Introduction
6de9cd9a
DN
201@c ---------------------------------------------------------------------
202
e6b38f67
BM
203@node Introduction
204@chapter Introduction
205
206@c The following duplicates the text on the TexInfo table of contents.
207@iftex
208This manual documents the use of @command{gfortran}, the GNU Fortran
209compiler. You can find in this manual how to invoke @command{gfortran},
210as well as its features and incompatibilities.
211
212@ifset DEVELOPMENT
213@emph{Warning:} This document, and the compiler it describes, are still
214under development. While efforts are made to keep it up-to-date, it
215might not accurately reflect the status of the most recent GNU Fortran
216compiler.
217@end ifset
218@end iftex
6de9cd9a 219
7fc15ba5 220The GNU Fortran compiler front end was
6de9cd9a
DN
221designed initially as a free replacement for,
222or alternative to, the unix @command{f95} command;
5724da63 223@command{gfortran} is the command you'll use to invoke the compiler.
6de9cd9a 224
e6b38f67
BM
225@menu
226* About GNU Fortran:: What you should know about the GNU Fortran compiler.
227* GNU Fortran and GCC:: You can compile Fortran, C, or other programs.
2b44ab8b 228* Preprocessing and conditional compilation:: The Fortran preprocessor
e6b38f67
BM
229* GNU Fortran and G77:: Why we chose to start from scratch.
230* Project Status:: Status of GNU Fortran, roadmap, proposed extensions.
231* Standards:: Standards supported by GNU Fortran.
232@end menu
233
234
235@c ---------------------------------------------------------------------
236@c About GNU Fortran
237@c ---------------------------------------------------------------------
238
239@node About GNU Fortran
240@section About GNU Fortran
241
7fc15ba5
BM
242The GNU Fortran compiler is still in an early state of development.
243It can generate code for most constructs and expressions,
6de9cd9a
DN
244but much work remains to be done.
245
7fc15ba5 246When the GNU Fortran compiler is finished,
6de9cd9a
DN
247it will do everything you expect from any decent compiler:
248
249@itemize @bullet
250@item
251Read a user's program,
252stored in a file and containing instructions written
26d29061 253in Fortran 77, Fortran 90, Fortran 95 or Fortran 2003.
6de9cd9a
DN
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 aren't as good writing machine code
265as they are at writing Fortran (or C++, Ada, or Java),
266because 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.
272When writing Fortran, it is easy to make big mistakes.
273The Fortran 90 requires that the compiler can point out
274mistakes to the user.
275An incorrect usage of the language causes an @dfn{error message}.
276
277The compiler will also attempt to diagnose cases where the
278user's program contains a correct usage of the language,
279but instructs the computer to do something questionable.
280This kind of diagnostics message is called a @dfn{warning message}.
281
282@item
283Provide optional information about the translation passes
284from the source code to machine code.
285This can help a user of the compiler to find the cause of
286certain bugs which may not be obvious in the source code,
287but may be more easily found at a lower level compiler output.
288It also helps developers to find bugs in the compiler itself.
289
290@item
291Provide information in the generated machine code that can
292make it easier to find bugs in the program (using a debugging tool,
293called a @dfn{debugger}, such as the GNU Debugger @command{gdb}).
294
295@item
296Locate and gather machine code already generated to
297perform actions requested by statements in the user's program.
298This machine code is organized into @dfn{modules} and is located
299and @dfn{linked} to the user program.
300@end itemize
301
7fc15ba5 302The GNU Fortran compiler consists of several components:
6de9cd9a
DN
303
304@itemize @bullet
305@item
306A version of the @command{gcc} command
307(which also might be installed as the system's @command{cc} command)
308that also understands and accepts Fortran source code.
309The @command{gcc} command is the @dfn{driver} program for
310all the languages in the GNU Compiler Collection (GCC);
311With @command{gcc},
5724da63 312you can compile the source code of any language for
6de9cd9a
DN
313which a front end is available in GCC.
314
315@item
316The @command{gfortran} command itself,
317which also might be installed as the
318system's @command{f95} command.
319@command{gfortran} is just another driver program,
7fc15ba5 320but specifically for the Fortran compiler only.
6de9cd9a
DN
321The difference with @command{gcc} is that @command{gfortran}
322will automatically link the correct libraries to your program.
323
324@item
325A collection of run-time libraries.
5724da63 326These libraries contain the machine code needed to support
6de9cd9a
DN
327capabilities of the Fortran language that are not directly
328provided by the machine code generated by the
329@command{gfortran} compilation phase,
330such as intrinsic functions and subroutines,
331and routines for interaction with files and the operating system.
332@c and mechanisms to spawn,
333@c unleash and pause threads in parallelized code.
334
335@item
336The Fortran compiler itself, (@command{f951}).
7fc15ba5 337This is the GNU Fortran parser and code generator,
6de9cd9a
DN
338linked to and interfaced with the GCC backend library.
339@command{f951} ``translates'' the source code to
340assembler code. You would typically not use this
341program directly;
342instead, the @command{gcc} or @command{gfortran} driver
343programs will call it for you.
344@end itemize
345
346
6de9cd9a 347@c ---------------------------------------------------------------------
7fc15ba5 348@c GNU Fortran and GCC
6de9cd9a
DN
349@c ---------------------------------------------------------------------
350
7fc15ba5 351@node GNU Fortran and GCC
e6b38f67 352@section GNU Fortran and GCC
6de9cd9a 353@cindex GNU Compiler Collection
de43c613
BM
354@cindex GCC
355
356GNU Fortran is a part of GCC, the @dfn{GNU Compiler Collection}. GCC
357consists of a collection of front ends for various languages, which
358translate the source code into a language-independent form called
359@dfn{GENERIC}. This is then processed by a common middle end which
360provides optimization, and then passed to one of a collection of back
361ends which generate code for different computer architectures and
362operating systems.
363
364Functionally, this is implemented with a driver program (@command{gcc})
365which provides the command-line interface for the compiler. It calls
366the relevant compiler front-end program (e.g., @command{f951} for
367Fortran) for each file in the source code, and then calls the assembler
368and linker as appropriate to produce the compiled output. In a copy of
369GCC which has been compiled with Fortran language support enabled,
7befd5d2
TB
370@command{gcc} will recognize files with @file{.f}, @file{.f90}, @file{.f95},
371and @file{.f03} extensions as Fortran source code, and compile it
de43c613
BM
372accordingly. A @command{gfortran} driver program is also provided,
373which is identical to @command{gcc} except that it automatically links
374the Fortran runtime libraries into the compiled program.
375
376This manual specifically documents the Fortran front end, which handles
377the programming language's syntax and semantics. The aspects of GCC
378which relate to the optimization passes and the back-end code generation
379are documented in the GCC manual; see
380@ref{Top,,Introduction,gcc,Using the GNU Compiler Collection (GCC)}.
381The two manuals together provide a complete reference for the GNU
382Fortran compiler.
6de9cd9a
DN
383
384
2b44ab8b
TB
385@c ---------------------------------------------------------------------
386@c Preprocessing and conditional compilation
387@c ---------------------------------------------------------------------
388
389@node Preprocessing and conditional compilation
390@section Preprocessing and conditional compilation
391@cindex CPP
392@cindex FPP
393@cindex Conditional compilation
394@cindex Preprocessing
395
396Many Fortran compilers including GNU Fortran allow to pass the source code
397through a C preprocessor (CPP; sometimes also called Fortran preprocessor,
398FPP) to allow for conditional compilation. In case of GNU Fortran
399this is the GNU C Preprocessor in the traditional mode. On systems with
400case-preserving file names, the preprocessor is automatically invoked if the
401file extension is @code{.F}, @code{.F90}, @code{.F95} or @code{.F03};
402otherwise use for fixed-format code the option @code{-x f77-cpp-input}
403and for free-format code @code{-x f95-cpp-input}. Invocation of the
404preprocessor can be suppressed using @code{-x f77} or @code{-x f95}.
405
406If the GNU Fortran invoked the preprocessor, @code{__GFORTRAN__}
407is defined and @code{__GNUC__}, @code{__GNUC_MINOR__} and
408@code{__GNUC_PATCHLEVEL__} can be used to determine the version of the
409compiler. See @ref{Top,,Overview,cpp,The C Preprocessor} for details.
410
411While CPP is the de-facto standard for preprocessing Fortran code,
412Part 3 of the Fortran 95 standard (ISO/IEC 1539-3:1998) defines
413Conditional Compilation, which is not widely used and not directly
414supported by the GNU Fortran compiler. You can use the program coco
415to preprocess such files (@uref{http://users.erols.com/dnagle/coco.html}).
416
417
6de9cd9a 418@c ---------------------------------------------------------------------
7fc15ba5 419@c GNU Fortran and G77
6de9cd9a
DN
420@c ---------------------------------------------------------------------
421
7fc15ba5 422@node GNU Fortran and G77
e6b38f67 423@section GNU Fortran and G77
6de9cd9a 424@cindex Fortran 77
e739dfac 425@cindex @command{g77}
6de9cd9a 426
e739dfac
DF
427The GNU Fortran compiler is the successor to @command{g77}, the Fortran
42877 front end included in GCC prior to version 4. It is an entirely new
429program that has been designed to provide Fortran 95 support and
430extensibility for future Fortran language standards, as well as providing
431backwards compatibility for Fortran 77 and nearly all of the GNU language
432extensions supported by @command{g77}.
6de9cd9a 433
6de9cd9a 434
6de9cd9a
DN
435@c ---------------------------------------------------------------------
436@c Project Status
437@c ---------------------------------------------------------------------
438
439@node Project Status
e6b38f67 440@section Project Status
6de9cd9a
DN
441
442@quotation
7fc15ba5 443As soon as @command{gfortran} can parse all of the statements correctly,
6de9cd9a
DN
444it will be in the ``larva'' state.
445When we generate code, the ``puppa'' state.
7fc15ba5 446When @command{gfortran} is done,
6de9cd9a
DN
447we'll see if it will be a beautiful butterfly,
448or just a big bug....
449
450--Andy Vaught, April 2000
451@end quotation
452
453The start of the GNU Fortran 95 project was announced on
454the GCC homepage in March 18, 2000
455(even though Andy had already been working on it for a while,
5724da63 456of course).
6de9cd9a 457
cf822c04
BM
458The GNU Fortran compiler is able to compile nearly all
459standard-compliant Fortran 95, Fortran 90, and Fortran 77 programs,
460including a number of standard and non-standard extensions, and can be
461used on real-world programs. In particular, the supported extensions
462include OpenMP, Cray-style pointers, and several Fortran 2003 features
463such as enumeration, stream I/O, and some of the enhancements to
464allocatable array support from TR 15581. However, it is still under
465development and has a few remaining rough edges.
466
467At present, the GNU Fortran compiler passes the
468@uref{http://www.fortran-2000.com/ArnaudRecipes/fcvs21_f95.html,
469NIST Fortran 77 Test Suite}, and produces acceptable results on the
470@uref{http://www.netlib.org/lapack/faq.html#1.21, LAPACK Test Suite}.
471It also provides respectable performance on
472the @uref{http://www.polyhedron.com/pb05.html, Polyhedron Fortran
473compiler benchmarks} and the
474@uref{http://www.llnl.gov/asci_benchmarks/asci/limited/lfk/README.html,
475Livermore Fortran Kernels test}. It has been used to compile a number of
476large real-world programs, including
477@uref{http://mysite.verizon.net/serveall/moene.pdf, the HIRLAM
478weather-forecasting code} and
479@uref{http://www.theochem.uwa.edu.au/tonto/, the Tonto quantum
26d29061
TB
480chemistry package}; see @url{http://gcc.gnu.org/wiki/GfortranApps} for an
481extended list.
cf822c04
BM
482
483Among other things, the GNU Fortran compiler is intended as a replacement
484for G77. At this point, nearly all programs that could be compiled with
485G77 can be compiled with GNU Fortran, although there are a few minor known
486regressions.
487
488The primary work remaining to be done on GNU Fortran falls into three
489categories: bug fixing (primarily regarding the treatment of invalid code
490and providing useful error messages), improving the compiler optimizations
491and the performance of compiled code, and extending the compiler to support
8556236b 492future standards---in particular, Fortran 2003.
cf822c04 493
6de9cd9a 494
c8cf50e4
BM
495@c ---------------------------------------------------------------------
496@c Standards
497@c ---------------------------------------------------------------------
6de9cd9a 498
c8cf50e4 499@node Standards
e6b38f67 500@section Standards
c8cf50e4 501@cindex Standards
6de9cd9a 502
c8cf50e4
BM
503The GNU Fortran compiler implements
504ISO/IEC 1539:1997 (Fortran 95). As such, it can also compile essentially all
505standard-compliant Fortran 90 and Fortran 77 programs. It also supports
506the ISO/IEC TR-15581 enhancements to allocatable arrays, and
507the @uref{http://www.openmp.org/drupal/mp-documents/spec25.pdf,
508OpenMP Application Program Interface v2.5} specification.
6de9cd9a 509
c8cf50e4
BM
510In the future, the GNU Fortran compiler may also support other standard
511variants of and extensions to the Fortran language. These include
512ISO/IEC 1539-1:2004 (Fortran 2003).
6de9cd9a 513
6de9cd9a 514
c8cf50e4 515@c =====================================================================
e6b38f67 516@c PART I: INVOCATION REFERENCE
c8cf50e4 517@c =====================================================================
6de9cd9a 518
c8cf50e4 519@tex
e6b38f67 520\part{I}{Invoking GNU Fortran}
c8cf50e4 521@end tex
6de9cd9a 522
c8cf50e4
BM
523@c ---------------------------------------------------------------------
524@c Compiler Options
525@c ---------------------------------------------------------------------
6de9cd9a 526
c8cf50e4 527@include invoke.texi
6de9cd9a 528
cf822c04
BM
529
530@c ---------------------------------------------------------------------
531@c Runtime
532@c ---------------------------------------------------------------------
533
eaa90d25
TK
534@node Runtime
535@chapter Runtime: Influencing runtime behavior with environment variables
e739dfac 536@cindex environment variable
eaa90d25 537
b82feea5 538The behavior of the @command{gfortran} can be influenced by
eaa90d25 539environment variables.
f5dc42bb
TK
540
541Malformed environment variables are silently ignored.
542
eaa90d25 543@menu
f5dc42bb
TK
544* GFORTRAN_STDIN_UNIT:: Unit number for standard input
545* GFORTRAN_STDOUT_UNIT:: Unit number for standard output
546* GFORTRAN_STDERR_UNIT:: Unit number for standard error
547* GFORTRAN_USE_STDERR:: Send library output to standard error
548* GFORTRAN_TMPDIR:: Directory for scratch files
6e34d7b8
JB
549* GFORTRAN_UNBUFFERED_n:: Don't buffer I/O for specific unit.
550* GFORTRAN_UNBUFFERED_ALL:: Don't buffer I/O for all units.
f5dc42bb
TK
551* GFORTRAN_SHOW_LOCUS:: Show location for runtime errors
552* GFORTRAN_OPTIONAL_PLUS:: Print leading + where permitted
553* GFORTRAN_DEFAULT_RECL:: Default record length for new files
554* GFORTRAN_LIST_SEPARATOR:: Separator for list output
eaa90d25 555* GFORTRAN_CONVERT_UNIT:: Set endianness for unformatted I/O
a0cb58b2
TB
556* GFORTRAN_ERROR_DUMPCORE:: Dump core on run-time errors
557* GFORTRAN_ERROR_BACKTRACE:: Show backtrace on run-time errors
eaa90d25
TK
558@end menu
559
f5dc42bb
TK
560@node GFORTRAN_STDIN_UNIT
561@section @env{GFORTRAN_STDIN_UNIT}---Unit number for standard input
562
563This environment variable can be used to select the unit number
564preconnected to standard input. This must be a positive integer.
565The default value is 5.
566
567@node GFORTRAN_STDOUT_UNIT
568@section @env{GFORTRAN_STDOUT_UNIT}---Unit number for standard output
569
570This environment variable can be used to select the unit number
571preconnected to standard output. This must be a positive integer.
572The default value is 6.
573
574@node GFORTRAN_STDERR_UNIT
575@section @env{GFORTRAN_STDERR_UNIT}---Unit number for standard error
576
577This environment variable can be used to select the unit number
578preconnected to standard error. This must be a positive integer.
579The default value is 0.
580
581@node GFORTRAN_USE_STDERR
582@section @env{GFORTRAN_USE_STDERR}---Send library output to standard error
583
584This environment variable controls where library output is sent.
585If the first letter is @samp{y}, @samp{Y} or @samp{1}, standard
586error is used. If the first letter is @samp{n}, @samp{N} or
587@samp{0}, standard output is used.
588
589@node GFORTRAN_TMPDIR
590@section @env{GFORTRAN_TMPDIR}---Directory for scratch files
591
592This environment variable controls where scratch files are
593created. If this environment variable is missing,
7fc15ba5 594GNU Fortran searches for the environment variable @env{TMP}. If
f5dc42bb
TK
595this is also missing, the default is @file{/tmp}.
596
6e34d7b8
JB
597@node GFORTRAN_UNBUFFERED_n
598@section @env{GFORTRAN_UNBUFFERED_n}---Don't buffer I/O on unit n
599
600Environment variables named @env{GFORTRAN_UNBUFFERED_n}, where
601@samp{n} is an integer, control whether I/O on unit @samp{n} is
602unbuffered. If the first letter is @samp{y}, @samp{Y} or @samp{1},
603I/O is unbuffered. This will slow down small sequential reads and
604writes. If the first letter is @samp{n}, @samp{N} or @samp{0}, I/O is
605buffered. This is the default.
606
f5dc42bb 607@node GFORTRAN_UNBUFFERED_ALL
6e34d7b8 608@section @env{GFORTRAN_UNBUFFERED_ALL}---Don't buffer I/O on all units
f5dc42bb 609
6e34d7b8
JB
610This environment variable controls whether all I/O is unbuffered. If
611the first letter is @samp{y}, @samp{Y} or @samp{1}, all I/O is
612unbuffered. This will slow down small sequential reads and writes. If
613the first letter is @samp{n}, @samp{N} or @samp{0}, I/O is buffered.
614This is the default.
f5dc42bb
TK
615
616@node GFORTRAN_SHOW_LOCUS
617@section @env{GFORTRAN_SHOW_LOCUS}---Show location for runtime errors
618
619If the first letter is @samp{y}, @samp{Y} or @samp{1}, filename and
620line numbers for runtime errors are printed. If the first letter is
621@samp{n}, @samp{N} or @samp{0}, don't print filename and line numbers
622for runtime errors. The default is to print the location.
623
624@node GFORTRAN_OPTIONAL_PLUS
625@section @env{GFORTRAN_OPTIONAL_PLUS}---Print leading + where permitted
626
627If the first letter is @samp{y}, @samp{Y} or @samp{1},
628a plus sign is printed
b82feea5 629where permitted by the Fortran standard. If the first letter
f5dc42bb
TK
630is @samp{n}, @samp{N} or @samp{0}, a plus sign is not printed
631in most cases. Default is not to print plus signs.
632
633@node GFORTRAN_DEFAULT_RECL
634@section @env{GFORTRAN_DEFAULT_RECL}---Default record length for new files
635
11de78ff
BM
636This environment variable specifies the default record length, in
637bytes, for files which are opened without a @code{RECL} tag in the
638@code{OPEN} statement. This must be a positive integer. The
639default value is 1073741824 bytes (1 GB).
f5dc42bb
TK
640
641@node GFORTRAN_LIST_SEPARATOR
642@section @env{GFORTRAN_LIST_SEPARATOR}---Separator for list output
643
644This environment variable specifies the separator when writing
645list-directed output. It may contain any number of spaces and
646at most one comma. If you specify this on the command line,
647be sure to quote spaces, as in
648@smallexample
649$ GFORTRAN_LIST_SEPARATOR=' , ' ./a.out
650@end smallexample
40746dcc 651when @command{a.out} is the compiled Fortran program that you want to run.
f5dc42bb
TK
652Default is a single space.
653
eaa90d25 654@node GFORTRAN_CONVERT_UNIT
f5dc42bb 655@section @env{GFORTRAN_CONVERT_UNIT}---Set endianness for unformatted I/O
eaa90d25 656
f5dc42bb 657By setting the @env{GFORTRAN_CONVERT_UNIT} variable, it is possible
eaa90d25 658to change the representation of data for unformatted files.
f5dc42bb 659The syntax for the @env{GFORTRAN_CONVERT_UNIT} variable is:
eaa90d25 660@smallexample
1941551a 661GFORTRAN_CONVERT_UNIT: mode | mode ';' exception | exception ;
eaa90d25
TK
662mode: 'native' | 'swap' | 'big_endian' | 'little_endian' ;
663exception: mode ':' unit_list | unit_list ;
664unit_list: unit_spec | unit_list unit_spec ;
665unit_spec: INTEGER | INTEGER '-' INTEGER ;
666@end smallexample
667The variable consists of an optional default mode, followed by
668a list of optional exceptions, which are separated by semicolons
669from the preceding default and each other. Each exception consists
670of a format and a comma-separated list of units. Valid values for
671the modes are the same as for the @code{CONVERT} specifier:
672
673@itemize @w{}
674@item @code{NATIVE} Use the native format. This is the default.
675@item @code{SWAP} Swap between little- and big-endian.
676@item @code{LITTLE_ENDIAN} Use the little-endian format
677 for unformatted files.
678@item @code{BIG_ENDIAN} Use the big-endian format for unformatted files.
679@end itemize
680A missing mode for an exception is taken to mean @code{BIG_ENDIAN}.
40746dcc 681Examples of values for @env{GFORTRAN_CONVERT_UNIT} are:
eaa90d25
TK
682@itemize @w{}
683@item @code{'big_endian'} Do all unformatted I/O in big_endian mode.
684@item @code{'little_endian;native:10-20,25'} Do all unformatted I/O
685in little_endian mode, except for units 10 to 20 and 25, which are in
686native format.
687@item @code{'10-20'} Units 10 to 20 are big-endian, the rest is native.
6de9cd9a
DN
688@end itemize
689
eaa90d25 690Setting the environment variables should be done on the command
40746dcc
BM
691line or via the @command{export}
692command for @command{sh}-compatible shells and via @command{setenv}
693for @command{csh}-compatible shells.
eaa90d25 694
40746dcc 695Example for @command{sh}:
eaa90d25
TK
696@smallexample
697$ gfortran foo.f90
698$ GFORTRAN_CONVERT_UNIT='big_endian;native:10-20' ./a.out
699@end smallexample
700
40746dcc 701Example code for @command{csh}:
eaa90d25
TK
702@smallexample
703% gfortran foo.f90
704% setenv GFORTRAN_CONVERT_UNIT 'big_endian;native:10-20'
705% ./a.out
706@end smallexample
707
708Using anything but the native representation for unformatted data
709carries a significant speed overhead. If speed in this area matters
710to you, it is best if you use this only for data that needs to be
711portable.
712
713@xref{CONVERT specifier}, for an alternative way to specify the
714data representation for unformatted files. @xref{Runtime Options}, for
715setting a default data representation for the whole program. The
40746dcc 716@code{CONVERT} specifier overrides the @option{-fconvert} compile options.
eaa90d25 717
1941551a
TB
718@emph{Note that the values specified via the GFORTRAN_CONVERT_UNIT
719environment variable will override the CONVERT specifier in the
720open statement}. This is to give control over data formats to
721users who do not have the source code of their program available.
722
a0cb58b2
TB
723@node GFORTRAN_ERROR_DUMPCORE
724@section @env{GFORTRAN_ERROR_DUMPCORE}---Dump core on run-time errors
725
726If the @env{GFORTRAN_ERROR_DUMPCORE} variable is set to
727@samp{y}, @samp{Y} or @samp{1} (only the first letter is relevant)
728then library run-time errors cause core dumps. To disable the core
729dumps, set the variable to @samp{n}, @samp{N}, @samp{0}. Default
730is not to core dump unless the @option{-fdump-core} compile option
731was used.
732
733@node GFORTRAN_ERROR_BACKTRACE
734@section @env{GFORTRAN_ERROR_BACKTRACE}---Show backtrace on run-time errors
735
736If the @env{GFORTRAN_ERROR_BACKTRACE} variable is set to
737@samp{y}, @samp{Y} or @samp{1} (only the first letter is relevant)
738then a backtrace is printed when a run-time error occurs.
739To disable the backtracing, set the variable to
740@samp{n}, @samp{N}, @samp{0}. Default is not to print a backtrace
741unless the @option{-fbacktrace} compile option
742was used.
c8cf50e4
BM
743
744@c =====================================================================
e6b38f67 745@c PART II: LANGUAGE REFERENCE
c8cf50e4
BM
746@c =====================================================================
747
748@tex
e6b38f67 749\part{II}{Language Reference}
c8cf50e4
BM
750@end tex
751
752@c ---------------------------------------------------------------------
753@c Fortran 2003 Status
754@c ---------------------------------------------------------------------
755
756@node Fortran 2003 status
757@chapter Fortran 2003 Status
758
759Although GNU Fortran focuses on implementing the Fortran 95
760standard for the time being, a few Fortran 2003 features are currently
761available.
762
763@itemize
764@item
765Intrinsics @code{command_argument_count}, @code{get_command},
766@code{get_command_argument}, @code{get_environment_variable}, and
767@code{move_alloc}.
768
769@item
e739dfac 770@cindex array, constructors
c8cf50e4
BM
771@cindex @code{[...]}
772Array constructors using square brackets. That is, @code{[...]} rather
773than @code{(/.../)}.
774
775@item
776@cindex @code{FLUSH} statement
e739dfac 777@cindex statement, @code{FLUSH}
c8cf50e4
BM
778@code{FLUSH} statement.
779
780@item
781@cindex @code{IOMSG=} specifier
782@code{IOMSG=} specifier for I/O statements.
783
784@item
785@cindex @code{ENUM} statement
786@cindex @code{ENUMERATOR} statement
e739dfac
DF
787@cindex statement, @code{ENUM}
788@cindex statement, @code{ENUMERATOR}
32864778 789@opindex @code{fshort-enums}
c8cf50e4
BM
790Support for the declaration of enumeration constants via the
791@code{ENUM} and @code{ENUMERATOR} statements. Interoperability with
792@command{gcc} is guaranteed also for the case where the
793@command{-fshort-enums} command line option is given.
794
795@item
796@cindex TR 15581
797TR 15581:
798@itemize
799@item
800@cindex @code{ALLOCATABLE} dummy arguments
801@code{ALLOCATABLE} dummy arguments.
802@item
803@cindex @code{ALLOCATABLE} function results
804@code{ALLOCATABLE} function results
805@item
806@cindex @code{ALLOCATABLE} components of derived types
807@code{ALLOCATABLE} components of derived types
808@end itemize
809
810@item
811@cindex @code{STREAM} I/O
812@cindex @code{ACCESS='STREAM'} I/O
813The @code{OPEN} statement supports the @code{ACCESS='STREAM'} specifier,
814allowing I/O without any record structure.
815
816@item
817Namelist input/output for internal files.
818
819@item
e739dfac
DF
820@cindex @code{PROTECTED} statement
821@cindex statement, @code{PROTECTED}
c8cf50e4
BM
822The @code{PROTECTED} statement and attribute.
823
824@item
e739dfac
DF
825@cindex @code{VALUE} statement
826@cindex statement, @code{VALUE}
c8cf50e4
BM
827The @code{VALUE} statement and attribute.
828
829@item
e739dfac
DF
830@cindex @code{VOLATILE} statement
831@cindex statement, @code{VOLATILE}
c8cf50e4
BM
832The @code{VOLATILE} statement and attribute.
833
834@item
e739dfac
DF
835@cindex @code{IMPORT} statement
836@cindex statement, @code{IMPORT}
c8cf50e4
BM
837The @code{IMPORT} statement, allowing to import
838host-associated derived types.
839
840@item
e739dfac
DF
841@cindex @code{USE, INTRINSIC} statement
842@cindex statement, @code{USE, INTRINSIC}
843@cindex @code{ISO_FORTRAN_ENV} statement
844@cindex statement, @code{ISO_FORTRAN_ENV}
c8cf50e4
BM
845@code{USE} statement with @code{INTRINSIC} and @code{NON_INTRINSIC}
846attribute; supported intrinsic modules: @code{ISO_FORTRAN_ENV},
847@code{OMP_LIB} and @code{OMP_LIB_KINDS}.
848
56bedf42
TB
849@item
850Renaming of operators in the @code{USE} statement.
851
c0eba481
TB
852@item
853@cindex ISO C Bindings
854Interoperability with C (ISO C Bindings)
855
c8cf50e4
BM
856@end itemize
857
858
294fbfc8
TS
859@c ---------------------------------------------------------------------
860@c Extensions
861@c ---------------------------------------------------------------------
862
863@c Maybe this chapter should be merged with the 'Standards' section,
864@c whenever that is written :-)
865
866@node Extensions
867@chapter Extensions
868@cindex Extension
869
7fc15ba5 870GNU Fortran implements a number of extensions over standard
294fbfc8 871Fortran. This chapter contains information on their syntax and
7fc15ba5 872meaning. There are currently two categories of GNU Fortran
c0309c74 873extensions, those that provide functionality beyond that provided
7fc15ba5 874by any standard, and those that are supported by GNU Fortran
c0309c74
RS
875purely for backward compatibility with legacy compilers. By default,
876@option{-std=gnu} allows the compiler to accept both types of
877extensions, but to warn about the use of the latter. Specifying
878either @option{-std=f95} or @option{-std=f2003} disables both types
879of extensions, and @option{-std=legacy} allows both without warning.
294fbfc8
TS
880
881@menu
882* Old-style kind specifications::
883* Old-style variable initialization::
670026fb 884* Extensions to namelist::
11de78ff 885* X format descriptor without count field::
ec8a1940 886* Commas in FORMAT specifications::
c9f4aa97 887* Missing period in FORMAT specifications::
ec8a1940 888* I/O item lists::
11de78ff 889* BOZ literal constants::
ec8a1940
RS
890* Real array indices::
891* Unary operators::
11de78ff 892* Implicitly convert LOGICAL and INTEGER values::
bc192c77 893* Hollerith constants support::
83d890b9 894* Cray pointers::
181c9f4a 895* CONVERT specifier::
6c7a4dfd 896* OpenMP::
d60e76db 897* Argument list functions::
294fbfc8 898@end menu
6de9cd9a 899
294fbfc8
TS
900@node Old-style kind specifications
901@section Old-style kind specifications
e739dfac 902@cindex kind, old-style
294fbfc8 903
b69862d1
BM
904GNU Fortran allows old-style kind specifications in declarations. These
905look like:
294fbfc8 906@smallexample
b69862d1 907 TYPESPEC*size x,y,z
294fbfc8 908@end smallexample
b2b81a3f 909@noindent
11de78ff 910where @code{TYPESPEC} is a basic type (@code{INTEGER}, @code{REAL},
b2b81a3f
BM
911etc.), and where @code{size} is a byte count corresponding to the
912storage size of a valid kind for that type. (For @code{COMPLEX}
913variables, @code{size} is the total size of the real and imaginary
914parts.) The statement then declares @code{x}, @code{y} and @code{z} to
915be of type @code{TYPESPEC} with the appropriate kind. This is
916equivalent to the standard-conforming declaration
294fbfc8
TS
917@smallexample
918 TYPESPEC(k) x,y,z
919@end smallexample
b2b81a3f 920@noindent
b69862d1
BM
921where @code{k} is equal to @code{size} for most types, but is equal to
922@code{size/2} for the @code{COMPLEX} type.
294fbfc8
TS
923
924@node Old-style variable initialization
925@section Old-style variable initialization
294fbfc8 926
7fc15ba5 927GNU Fortran allows old-style initialization of variables of the
294fbfc8
TS
928form:
929@smallexample
11de78ff
BM
930 INTEGER i/1/,j/2/
931 REAL x(2,2) /3*0.,1./
294fbfc8 932@end smallexample
11de78ff 933The syntax for the initializers is as for the @code{DATA} statement, but
294fbfc8 934unlike in a @code{DATA} statement, an initializer only applies to the
11de78ff
BM
935variable immediately preceding the initialization. In other words,
936something like @code{INTEGER I,J/2,3/} is not valid. This style of
937initialization is only allowed in declarations without double colons
938(@code{::}); the double colons were introduced in Fortran 90, which also
0979f01d 939introduced a standard syntax for initializing variables in type
11de78ff
BM
940declarations.
941
942Examples of standard-conforming code equivalent to the above example
943are:
294fbfc8
TS
944@smallexample
945! Fortran 90
11de78ff
BM
946 INTEGER :: i = 1, j = 2
947 REAL :: x(2,2) = RESHAPE((/0.,0.,0.,1./),SHAPE(x))
294fbfc8 948! Fortran 77
11de78ff
BM
949 INTEGER i, j
950 REAL x(2,2)
951 DATA i/1/, j/2/, x/3*0.,1./
294fbfc8 952@end smallexample
6de9cd9a 953
11de78ff
BM
954Note that variables which are explicitly initialized in declarations
955or in @code{DATA} statements automatically acquire the @code{SAVE}
956attribute.
9618502b 957
670026fb
PT
958@node Extensions to namelist
959@section Extensions to namelist
960@cindex Namelist
961
7fc15ba5 962GNU Fortran fully supports the Fortran 95 standard for namelist I/O
670026fb
PT
963including array qualifiers, substrings and fully qualified derived types.
964The output from a namelist write is compatible with namelist read. The
965output has all names in upper case and indentation to column 1 after the
966namelist name. Two extensions are permitted:
967
11de78ff 968Old-style use of @samp{$} instead of @samp{&}
670026fb
PT
969@smallexample
970$MYNML
971 X(:)%Y(2) = 1.0 2.0 3.0
972 CH(1:4) = "abcd"
973$END
974@end smallexample
975
11de78ff
BM
976It should be noted that the default terminator is @samp{/} rather than
977@samp{&END}.
670026fb
PT
978
979Querying of the namelist when inputting from stdin. After at least
11de78ff 980one space, entering @samp{?} sends to stdout the namelist name and the names of
670026fb
PT
981the variables in the namelist:
982@smallexample
11de78ff 983 ?
670026fb
PT
984
985&mynml
986 x
987 x%y
988 ch
989&end
990@end smallexample
991
11de78ff
BM
992Entering @samp{=?} outputs the namelist to stdout, as if
993@code{WRITE(*,NML = mynml)} had been called:
670026fb
PT
994@smallexample
995=?
996
997&MYNML
998 X(1)%Y= 0.000000 , 1.000000 , 0.000000 ,
999 X(2)%Y= 0.000000 , 2.000000 , 0.000000 ,
1000 X(3)%Y= 0.000000 , 3.000000 , 0.000000 ,
1001 CH=abcd, /
1002@end smallexample
1003
5724da63 1004To aid this dialog, when input is from stdin, errors send their
11de78ff 1005messages to stderr and execution continues, even if @code{IOSTAT} is set.
670026fb 1006
11de78ff
BM
1007@code{PRINT} namelist is permitted. This causes an error if
1008@option{-std=f95} is used.
21d7d31f
PT
1009@smallexample
1010PROGRAM test_print
1011 REAL, dimension (4) :: x = (/1.0, 2.0, 3.0, 4.0/)
1012 NAMELIST /mynml/ x
1013 PRINT mynml
1014END PROGRAM test_print
1015@end smallexample
1016
11de78ff
BM
1017Expanded namelist reads are permitted. This causes an error if
1018@option{-std=f95} is used. In the following example, the first element
1019of the array will be given the value 0.00 and the two succeeding
1020elements will be given the values 1.00 and 2.00.
c9f4aa97
JD
1021@smallexample
1022&MYNML
1023 X(1,1) = 0.00 , 1.00 , 2.00
1024/
1025@end smallexample
1026
11de78ff
BM
1027@node X format descriptor without count field
1028@section @code{X} format descriptor without count field
ec8a1940 1029
11de78ff
BM
1030To support legacy codes, GNU Fortran permits the count field of the
1031@code{X} edit descriptor in @code{FORMAT} statements to be omitted.
1032When omitted, the count is implicitly assumed to be one.
ec8a1940
RS
1033
1034@smallexample
1035 PRINT 10, 2, 3
103610 FORMAT (I1, X, I1)
1037@end smallexample
1038
1039@node Commas in FORMAT specifications
11de78ff 1040@section Commas in @code{FORMAT} specifications
ec8a1940 1041
7fc15ba5 1042To support legacy codes, GNU Fortran allows the comma separator
ec8a1940 1043to be omitted immediately before and after character string edit
11de78ff 1044descriptors in @code{FORMAT} statements.
ec8a1940
RS
1045
1046@smallexample
1047 PRINT 10, 2, 3
104810 FORMAT ('FOO='I1' BAR='I2)
1049@end smallexample
1050
c9f4aa97
JD
1051
1052@node Missing period in FORMAT specifications
11de78ff 1053@section Missing period in @code{FORMAT} specifications
c9f4aa97 1054
7fc15ba5 1055To support legacy codes, GNU Fortran allows missing periods in format
11de78ff
BM
1056specifications if and only if @option{-std=legacy} is given on the
1057command line. This is considered non-conforming code and is
1058discouraged.
c9f4aa97
JD
1059
1060@smallexample
1061 REAL :: value
1062 READ(*,10) value
106310 FORMAT ('F4')
1064@end smallexample
1065
ec8a1940
RS
1066@node I/O item lists
1067@section I/O item lists
1068@cindex I/O item lists
1069
7fc15ba5 1070To support legacy codes, GNU Fortran allows the input item list
11de78ff
BM
1071of the @code{READ} statement, and the output item lists of the
1072@code{WRITE} and @code{PRINT} statements, to start with a comma.
ec8a1940 1073
11de78ff
BM
1074@node BOZ literal constants
1075@section BOZ literal constants
1076@cindex BOZ literal constants
ec8a1940 1077
11de78ff 1078As an extension, GNU Fortran allows hexadecimal BOZ literal constants to
ec8a1940 1079be specified using the X prefix, in addition to the standard Z prefix.
11de78ff
BM
1080BOZ literal constants can also be specified by adding a suffix to the
1081string. For example, @code{Z'ABC'} and @code{'ABC'Z} are equivalent.
1082
1083The Fortran standard restricts the appearance of a BOZ literal constant
1084to the @code{DATA} statement, and it is expected to be assigned to an
1085@code{INTEGER} variable. GNU Fortran permits a BOZ literal to appear in
1086any initialization expression as well as assignment statements.
1087
1088Attempts to use a BOZ literal constant to do a bitwise initialization of
1089a variable can lead to confusion. A BOZ literal constant is converted
1090to an @code{INTEGER} value with the kind type with the largest decimal
1091representation, and this value is then converted numerically to the type
1092and kind of the variable in question. Thus, one should not expect a
1093bitwise copy of the BOZ literal constant to be assigned to a @code{REAL}
1094variable.
1095
1096Similarly, initializing an @code{INTEGER} variable with a statement such
1097as @code{DATA i/Z'FFFFFFFF'/} will produce an integer overflow rather
1098than the desired result of @math{-1} when @code{i} is a 32-bit integer
1099on a system that supports 64-bit integers. The @samp{-fno-range-check}
1100option can be used as a workaround for legacy code that initializes
1101integers in this manner.
ec8a1940
RS
1102
1103@node Real array indices
1104@section Real array indices
e739dfac 1105@cindex array, indices of type real
ec8a1940 1106
11de78ff
BM
1107As an extension, GNU Fortran allows the use of @code{REAL} expressions
1108or variables as array indices.
ec8a1940
RS
1109
1110@node Unary operators
1111@section Unary operators
e739dfac 1112@cindex operators, unary
ec8a1940 1113
11de78ff
BM
1114As an extension, GNU Fortran allows unary plus and unary minus operators
1115to appear as the second operand of binary arithmetic operators without
1116the need for parenthesis.
ec8a1940
RS
1117
1118@smallexample
1119 X = Y * -Z
1120@end smallexample
1121
11de78ff
BM
1122@node Implicitly convert LOGICAL and INTEGER values
1123@section Implicitly convert @code{LOGICAL} and @code{INTEGER} values
e739dfac
DF
1124@cindex conversion, to integer
1125@cindex conversion, to logical
c3a29423 1126
11de78ff
BM
1127As an extension for backwards compatibility with other compilers, GNU
1128Fortran allows the implicit conversion of @code{LOGICAL} values to
1129@code{INTEGER} values and vice versa. When converting from a
1130@code{LOGICAL} to an @code{INTEGER}, @code{.FALSE.} is interpreted as
1131zero, and @code{.TRUE.} is interpreted as one. When converting from
1132@code{INTEGER} to @code{LOGICAL}, the value zero is interpreted as
49de9e73 1133@code{.FALSE.} and any nonzero value is interpreted as @code{.TRUE.}.
c3a29423
RS
1134
1135@smallexample
11de78ff
BM
1136 INTEGER :: i = 1
1137 IF (i) PRINT *, 'True'
c3a29423
RS
1138@end smallexample
1139
bc192c77
FW
1140@node Hollerith constants support
1141@section Hollerith constants support
1142@cindex Hollerith constants
1143
11de78ff
BM
1144GNU Fortran supports Hollerith constants in assignments, function
1145arguments, and @code{DATA} and @code{ASSIGN} statements. A Hollerith
0979f01d 1146constant is written as a string of characters preceded by an integer
11de78ff
BM
1147constant indicating the character count, and the letter @code{H} or
1148@code{h}, and stored in bytewise fashion in a numeric (@code{INTEGER},
1149@code{REAL}, or @code{complex}) or @code{LOGICAL} variable. The
1150constant will be padded or truncated to fit the size of the variable in
1151which it is stored.
bc192c77 1152
11de78ff 1153Examples of valid uses of Hollerith constants:
bc192c77 1154@smallexample
11de78ff
BM
1155 complex*16 x(2)
1156 data x /16Habcdefghijklmnop, 16Hqrstuvwxyz012345/
1157 x(1) = 16HABCDEFGHIJKLMNOP
1158 call foo (4h abc)
bc192c77
FW
1159@end smallexample
1160
1161Invalid Hollerith constants examples:
1162@smallexample
11de78ff
BM
1163 integer*4 a
1164 a = 8H12345678 ! Valid, but the Hollerith constant will be truncated.
1165 a = 0H ! At least one character is needed.
bc192c77
FW
1166@end smallexample
1167
11de78ff
BM
1168In general, Hollerith constants were used to provide a rudimentary
1169facility for handling character strings in early Fortran compilers,
1170prior to the introduction of @code{CHARACTER} variables in Fortran 77;
1171in those cases, the standard-compliant equivalent is to convert the
1172program to use proper character strings. On occasion, there may be a
1173case where the intent is specifically to initialize a numeric variable
1174with a given byte sequence. In these cases, the same result can be
1175obtained by using the @code{TRANSFER} statement, as in this example.
1176@smallexample
1177 INTEGER(KIND=4) :: a
1178 a = TRANSFER ("abcd", a) ! equivalent to: a = 4Habcd
1179@end smallexample
1180
1181
83d890b9
AL
1182@node Cray pointers
1183@section Cray pointers
e739dfac 1184@cindex pointer, cray
83d890b9
AL
1185
1186Cray pointers are part of a non-standard extension that provides a
1187C-like pointer in Fortran. This is accomplished through a pair of
1188variables: an integer "pointer" that holds a memory address, and a
1189"pointee" that is used to dereference the pointer.
1190
1191Pointer/pointee pairs are declared in statements of the form:
1192@smallexample
1193 pointer ( <pointer> , <pointee> )
1194@end smallexample
1195or,
1196@smallexample
1197 pointer ( <pointer1> , <pointee1> ), ( <pointer2> , <pointee2> ), ...
1198@end smallexample
1199The pointer is an integer that is intended to hold a memory address.
1200The pointee may be an array or scalar. A pointee can be an assumed
8556236b 1201size array---that is, the last dimension may be left unspecified by
11de78ff
BM
1202using a @code{*} in place of a value---but a pointee cannot be an
1203assumed shape array. No space is allocated for the pointee.
83d890b9
AL
1204
1205The pointee may have its type declared before or after the pointer
1206statement, and its array specification (if any) may be declared
1207before, during, or after the pointer statement. The pointer may be
1208declared as an integer prior to the pointer statement. However, some
1209machines have default integer sizes that are different than the size
1210of a pointer, and so the following code is not portable:
1211@smallexample
1212 integer ipt
1213 pointer (ipt, iarr)
1214@end smallexample
1215If a pointer is declared with a kind that is too small, the compiler
1216will issue a warning; the resulting binary will probably not work
1217correctly, because the memory addresses stored in the pointers may be
1218truncated. It is safer to omit the first line of the above example;
1219if explicit declaration of ipt's type is omitted, then the compiler
1220will ensure that ipt is an integer variable large enough to hold a
1221pointer.
1222
1223Pointer arithmetic is valid with Cray pointers, but it is not the same
1224as C pointer arithmetic. Cray pointers are just ordinary integers, so
1225the user is responsible for determining how many bytes to add to a
1226pointer in order to increment it. Consider the following example:
1227@smallexample
1228 real target(10)
1229 real pointee(10)
1230 pointer (ipt, pointee)
1231 ipt = loc (target)
1232 ipt = ipt + 1
1233@end smallexample
11de78ff
BM
1234The last statement does not set @code{ipt} to the address of
1235@code{target(1)}, as it would in C pointer arithmetic. Adding @code{1}
1236to @code{ipt} just adds one byte to the address stored in @code{ipt}.
83d890b9
AL
1237
1238Any expression involving the pointee will be translated to use the
b122dc6a 1239value stored in the pointer as the base address.
83d890b9
AL
1240
1241To get the address of elements, this extension provides an intrinsic
11de78ff
BM
1242function @code{LOC()}. The @code{LOC()} function is equivalent to the
1243@code{&} operator in C, except the address is cast to an integer type:
83d890b9
AL
1244@smallexample
1245 real ar(10)
1246 pointer(ipt, arpte(10))
1247 real arpte
1248 ipt = loc(ar) ! Makes arpte is an alias for ar
1249 arpte(1) = 1.0 ! Sets ar(1) to 1.0
1250@end smallexample
3397327c
BM
1251The pointer can also be set by a call to the @code{MALLOC} intrinsic
1252(see @ref{MALLOC}).
1253
83d890b9
AL
1254Cray pointees often are used to alias an existing variable. For
1255example:
1256@smallexample
1257 integer target(10)
1258 integer iarr(10)
1259 pointer (ipt, iarr)
1260 ipt = loc(target)
1261@end smallexample
11de78ff
BM
1262As long as @code{ipt} remains unchanged, @code{iarr} is now an alias for
1263@code{target}. The optimizer, however, will not detect this aliasing, so
1264it is unsafe to use @code{iarr} and @code{target} simultaneously. Using
1265a pointee in any way that violates the Fortran aliasing rules or
1266assumptions is illegal. It is the user's responsibility to avoid doing
1267this; the compiler works under the assumption that no such aliasing
1268occurs.
1269
1270Cray pointers will work correctly when there is no aliasing (i.e., when
1271they are used to access a dynamically allocated block of memory), and
1272also in any routine where a pointee is used, but any variable with which
1273it shares storage is not used. Code that violates these rules may not
1274run as the user intends. This is not a bug in the optimizer; any code
1275that violates the aliasing rules is illegal. (Note that this is not
1276unique to GNU Fortran; any Fortran compiler that supports Cray pointers
1277will ``incorrectly'' optimize code with illegal aliasing.)
1278
1279There are a number of restrictions on the attributes that can be applied
1280to Cray pointers and pointees. Pointees may not have the
1281@code{ALLOCATABLE}, @code{INTENT}, @code{OPTIONAL}, @code{DUMMY},
1282@code{TARGET}, @code{INTRINSIC}, or @code{POINTER} attributes. Pointers
1283may not have the @code{DIMENSION}, @code{POINTER}, @code{TARGET},
1284@code{ALLOCATABLE}, @code{EXTERNAL}, or @code{INTRINSIC} attributes.
83d890b9
AL
1285Pointees may not occur in more than one pointer statement. A pointee
1286cannot be a pointer. Pointees cannot occur in equivalence, common, or
1287data statements.
1288
11de78ff
BM
1289A Cray pointer may also point to a function or a subroutine. For
1290example, the following excerpt is valid:
7074ea72
AL
1291@smallexample
1292 implicit none
1293 external sub
1294 pointer (subptr,subpte)
1295 external subpte
1296 subptr = loc(sub)
1297 call subpte()
1298 [...]
1299 subroutine sub
1300 [...]
1301 end subroutine sub
1302@end smallexample
1303
83d890b9
AL
1304A pointer may be modified during the course of a program, and this
1305will change the location to which the pointee refers. However, when
1306pointees are passed as arguments, they are treated as ordinary
1307variables in the invoked function. Subsequent changes to the pointer
1308will not change the base address of the array that was passed.
1309
181c9f4a
TK
1310@node CONVERT specifier
1311@section CONVERT specifier
1312@cindex CONVERT specifier
1313
7fc15ba5 1314GNU Fortran allows the conversion of unformatted data between little-
181c9f4a 1315and big-endian representation to facilitate moving of data
eaa90d25 1316between different systems. The conversion can be indicated with
181c9f4a 1317the @code{CONVERT} specifier on the @code{OPEN} statement.
eaa90d25
TK
1318@xref{GFORTRAN_CONVERT_UNIT}, for an alternative way of specifying
1319the data format via an environment variable.
181c9f4a
TK
1320
1321Valid values for @code{CONVERT} are:
1322@itemize @w{}
1323@item @code{CONVERT='NATIVE'} Use the native format. This is the default.
1324@item @code{CONVERT='SWAP'} Swap between little- and big-endian.
eaa90d25 1325@item @code{CONVERT='LITTLE_ENDIAN'} Use the little-endian representation
181c9f4a 1326 for unformatted files.
eaa90d25 1327@item @code{CONVERT='BIG_ENDIAN'} Use the big-endian representation for
181c9f4a
TK
1328 unformatted files.
1329@end itemize
1330
1331Using the option could look like this:
1332@smallexample
1333 open(file='big.dat',form='unformatted',access='sequential', &
1334 convert='big_endian')
1335@end smallexample
1336
1337The value of the conversion can be queried by using
1338@code{INQUIRE(CONVERT=ch)}. The values returned are
1339@code{'BIG_ENDIAN'} and @code{'LITTLE_ENDIAN'}.
1340
1341@code{CONVERT} works between big- and little-endian for
1342@code{INTEGER} values of all supported kinds and for @code{REAL}
8a6c4339 1343on IEEE systems of kinds 4 and 8. Conversion between different
181c9f4a 1344``extended double'' types on different architectures such as
7fc15ba5 1345m68k and x86_64, which GNU Fortran
11de78ff
BM
1346supports as @code{REAL(KIND=10)} and @code{REAL(KIND=16)}, will
1347probably not work.
181c9f4a 1348
eaa90d25
TK
1349@emph{Note that the values specified via the GFORTRAN_CONVERT_UNIT
1350environment variable will override the CONVERT specifier in the
1351open statement}. This is to give control over data formats to
11de78ff 1352users who do not have the source code of their program available.
eaa90d25
TK
1353
1354Using anything but the native representation for unformatted data
1355carries a significant speed overhead. If speed in this area matters
1356to you, it is best if you use this only for data that needs to be
1357portable.
1358
6c7a4dfd
JJ
1359@node OpenMP
1360@section OpenMP
1361@cindex OpenMP
1362
7fc15ba5 1363GNU Fortran attempts to be OpenMP Application Program Interface v2.5
40746dcc 1364compatible when invoked with the @option{-fopenmp} option. GNU Fortran
deeddce6 1365then generates parallelized code according to the OpenMP directives
6c7a4dfd 1366used in the source. The OpenMP Fortran runtime library
40746dcc 1367routines are provided both in a form of a Fortran 90 module named
6c7a4dfd 1368@code{omp_lib} and in a form of a Fortran @code{include} file named
40746dcc 1369@file{omp_lib.h}.
6c7a4dfd
JJ
1370
1371For details refer to the actual
1372@uref{http://www.openmp.org/drupal/mp-documents/spec25.pdf,
1373OpenMP Application Program Interface v2.5} specification.
1374
d60e76db
PT
1375@node Argument list functions
1376@section Argument list functions %VAL, %REF and %LOC
e739dfac
DF
1377@cindex argument list functions
1378@cindex %VAL
1379@cindex %REF
1380@cindex %LOC
d60e76db
PT
1381
1382GNU Fortran supports argument list functions @code{%VAL}, @code{%REF}
1383and @code{%LOC} statements, for backward compatibility with g77.
1384It is recommended that these should be used only for code that is
1385accessing facilities outside of GNU Fortran, such as operating system
1386or windowing facilities. It is best to constrain such uses to isolated
1387portions of a program--portions that deal specifically and exclusively
1388with low-level, system-dependent facilities. Such portions might well
1389provide a portable interface for use by the program as a whole, but are
1390themselves not portable, and should be thoroughly tested each time they
1391are rebuilt using a new compiler or version of a compiler.
1392
1393@code{%VAL} passes a scalar argument by value, @code{%REF} passes it by
1394reference and @code{%LOC} passes its memory location. Since gfortran
1395already passes scalar arguments by reference, @code{%REF} is in effect
1396a do-nothing. @code{%LOC} has the same effect as a fortran pointer.
1397
1398An example of passing an argument by value to a C subroutine foo.:
1399@smallexample
1400C
1401C prototype void foo_ (float x);
1402C
1403 external foo
1404 real*4 x
1405 x = 3.14159
1406 call foo (%VAL (x))
1407 end
1408@end smallexample
1409
1410For details refer to the g77 manual
1411@uref{http://gcc.gnu.org/onlinedocs/gcc-3.4.6/g77/index.html#Top}.
1412
1413Also, the gfortran testsuite c_by_val.f and its partner c_by_val.c are
1414worth a look.
1415
a63dad5b 1416@c ---------------------------------------------------------------------
c8cf50e4 1417@c Intrinsic Procedures
a63dad5b
TS
1418@c ---------------------------------------------------------------------
1419
c8cf50e4
BM
1420@include intrinsic.texi
1421
1422
1423@tex
1424\blankpart
1425@end tex
1426
6de9cd9a
DN
1427@c ---------------------------------------------------------------------
1428@c Contributing
1429@c ---------------------------------------------------------------------
1430
1431@node Contributing
c8cf50e4 1432@unnumbered Contributing
6de9cd9a
DN
1433@cindex Contributing
1434
1435Free software is only possible if people contribute to efforts
1436to create it.
1437We're always in need of more people helping out with ideas
1438and comments, writing documentation and contributing code.
1439
7fc15ba5 1440If you want to contribute to GNU Fortran,
6de9cd9a
DN
1441have a look at the long lists of projects you can take on.
1442Some of these projects are small,
1443some of them are large;
1444some are completely orthogonal to the rest of what is
7fc15ba5 1445happening on GNU Fortran,
6de9cd9a
DN
1446but others are ``mainstream'' projects in need of enthusiastic hackers.
1447All of these projects are important!
1448We'll eventually get around to the things here,
1449but they are also things doable by someone who is willing and able.
1450
1451@menu
1452* Contributors::
1453* Projects::
c8cf50e4 1454* Proposed Extensions::
6de9cd9a
DN
1455@end menu
1456
1457
1458@node Contributors
7fc15ba5 1459@section Contributors to GNU Fortran
6de9cd9a
DN
1460@cindex Contributors
1461@cindex Credits
1462@cindex Authors
1463
1464Most of the parser was hand-crafted by @emph{Andy Vaught}, who is
1465also the initiator of the whole project. Thanks Andy!
1466Most of the interface with GCC was written by @emph{Paul Brook}.
1467
1468The following individuals have contributed code and/or
7fc15ba5 1469ideas and significant help to the GNU Fortran project
ed499b9f 1470(in no particular order):
6de9cd9a
DN
1471
1472@itemize @minus
1473@item Andy Vaught
1474@item Katherine Holcomb
deeddce6 1475@item Tobias Schl@"uter
6de9cd9a
DN
1476@item Steven Bosscher
1477@item Toon Moene
1478@item Tim Prince
1479@item Niels Kristian Bech Jensen
1480@item Steven Johnson
1481@item Paul Brook
1482@item Feng Wang
1483@item Bud Davis
cf6ae955 1484@item Paul Thomas
deeddce6
SK
1485@item Fran@,{c}ois-Xavier Coudert
1486@item Steven G. Kargl
cf6ae955 1487@item Jerry Delisle
13679135 1488@item Janne Blomqvist
cf6ae955
SB
1489@item Erik Edelmann
1490@item Thomas Koenig
1491@item Asher Langton
deeddce6
SK
1492@item Jakub Jelinek
1493@item Roger Sayle
1494@item H.J. Lu
1495@item Richard Henderson
1496@item Richard Sandiford
1497@item Richard Guenther
1498@item Bernhard Fischer
6de9cd9a
DN
1499@end itemize
1500
1501The following people have contributed bug reports,
1502smaller or larger patches,
1503and much needed feedback and encouragement for the
7fc15ba5 1504GNU Fortran project:
6de9cd9a
DN
1505
1506@itemize @minus
1507@item Erik Schnetter
1508@item Bill Clodius
1509@item Kate Hedstrom
1510@end itemize
1511
1512Many other individuals have helped debug,
7fc15ba5 1513test and improve the GNU Fortran compiler over the past few years,
ed499b9f 1514and we welcome you to do the same!
6de9cd9a
DN
1515If you already have done so,
1516and you would like to see your name listed in the
1517list above, please contact us.
1518
1519
1520@node Projects
1521@section Projects
1522
1523@table @emph
1524
1525@item Help build the test suite
1526Solicit more code for donation to the test suite.
1527We can keep code private on request.
1528
1529@item Bug hunting/squishing
1530Find bugs and write more test cases!
1531Test cases are especially very welcome,
1532because it allows us to concentrate on fixing bugs
1533instead of isolating them.
1534
1535@item Smaller projects (``bug'' fixes):
1536 @itemize @minus
1537 @item Allow init exprs to be numbers raised to integer powers.
1538 @item Implement correct rounding.
1539 @item Implement F restrictions on Fortran 95 syntax.
1540 @item See about making Emacs-parsable error messages.
1541 @end itemize
1542@end table
1543
1544If you wish to work on the runtime libraries,
1545please contact a project maintainer.
1546@c TODO: email!
1547
1548
c8cf50e4
BM
1549@node Proposed Extensions
1550@section Proposed Extensions
6de9cd9a 1551
c8cf50e4
BM
1552Here's a list of proposed extensions for the GNU Fortran compiler, in no particular
1553order. Most of these are necessary to be fully compatible with
1554existing Fortran compilers, but they are not part of the official
1555J3 Fortran 95 standard.
6de9cd9a 1556
c8cf50e4
BM
1557@subsection Compiler extensions:
1558@itemize @bullet
1559@item
1560User-specified alignment rules for structures.
6de9cd9a 1561
c8cf50e4
BM
1562@item
1563Flag to generate @code{Makefile} info.
e014df90 1564
c8cf50e4
BM
1565@item
1566Automatically extend single precision constants to double.
e014df90 1567
c8cf50e4
BM
1568@item
1569Compile code that conserves memory by dynamically allocating common and
1570module storage either on stack or heap.
e014df90 1571
c8cf50e4
BM
1572@item
1573Compile flag to generate code for array conformance checking (suggest -CC).
e014df90 1574
c8cf50e4
BM
1575@item
1576User control of symbol names (underscores, etc).
e014df90 1577
c8cf50e4
BM
1578@item
1579Compile setting for maximum size of stack frame size before spilling
1580parts to static or heap.
e014df90 1581
a63dad5b 1582@item
c8cf50e4 1583Flag to force local variables into static space.
e27edcd4
TK
1584
1585@item
c8cf50e4 1586Flag to force local variables onto stack.
a63dad5b
TS
1587
1588@item
c8cf50e4 1589Flag for maximum errors before ending compile.
a63dad5b 1590
8e119f1b 1591@item
c8cf50e4
BM
1592Option to initialize otherwise uninitialized integer and floating
1593point variables.
1594@end itemize
1595
1596
1597@subsection Environment Options
1598@itemize @bullet
aa08038d 1599@item
c8cf50e4
BM
1600Pluggable library modules for random numbers, linear algebra.
1601LA should use BLAS calling conventions.
1602
8e119f1b 1603@item
c8cf50e4
BM
1604Environment variables controlling actions on arithmetic exceptions like
1605overflow, underflow, precision loss---Generate NaN, abort, default.
1606action.
1607
da1e2517 1608@item
c8cf50e4 1609Set precision for fp units that support it (i387).
aa08038d 1610
ffcba571 1611@item
c8cf50e4 1612Variable for setting fp rounding mode.
ffcba571 1613
08d7f64e 1614@item
c8cf50e4
BM
1615Variable to fill uninitialized variables with a user-defined bit
1616pattern.
08d7f64e 1617
669353d5 1618@item
c8cf50e4
BM
1619Environment variable controlling filename that is opened for that unit
1620number.
669353d5
TB
1621
1622@item
c8cf50e4 1623Environment variable to clear/trash memory being freed.
669353d5 1624
08d7f64e 1625@item
c8cf50e4 1626Environment variable to control tracing of allocations and frees.
ffcba571 1627
8998be20 1628@item
c8cf50e4 1629Environment variable to display allocated memory at normal program end.
8998be20 1630
669353d5 1631@item
c8cf50e4
BM
1632Environment variable for filename for * IO-unit.
1633
1634@item
1635Environment variable for temporary file directory.
1636
1637@item
1638Environment variable forcing standard output to be line buffered (unix).
ffcba571 1639
e014df90
JB
1640@end itemize
1641
1642
a63dad5b
TS
1643@c ---------------------------------------------------------------------
1644@c GNU General Public License
1645@c ---------------------------------------------------------------------
1646
1647@include gpl.texi
1648
1649
1650
1651@c ---------------------------------------------------------------------
1652@c GNU Free Documentation License
1653@c ---------------------------------------------------------------------
1654
1655@include fdl.texi
1656
1657
1658
1659@c ---------------------------------------------------------------------
1660@c Funding Free Software
1661@c ---------------------------------------------------------------------
1662
1663@include funding.texi
1664
e014df90 1665@c ---------------------------------------------------------------------
32864778 1666@c Indices
e014df90 1667@c ---------------------------------------------------------------------
6de9cd9a 1668
32864778 1669@node Option Index
e739dfac 1670@unnumbered Option Index
67948fd2
BM
1671@command{gfortran}'s command line options are indexed here without any
1672initial @samp{-} or @samp{--}. Where an option has both positive and
1673negative forms (such as -foption and -fno-option), relevant entries in
1674the manual are indexed under the most appropriate form; it may sometimes
1675be useful to look up both forms.
32864778
DF
1676@printindex op
1677
1678@node Keyword Index
e739dfac 1679@unnumbered Keyword Index
6de9cd9a
DN
1680@printindex cp
1681
1682@bye