1 \input texinfo @c -*-texinfo-*-
3 @setfilename gfortran.info
4 @set copyrights-gfortran 1999-2008
6 @include gcc-common.texi
8 @settitle The GNU Fortran Compiler
10 @c Create a separate index for command line options
12 @c Merge the standard indexes into a single one.
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.
28 \vglue\titlepagetopglue
30 \leftline{Part #1:@* #2}
31 \vskip4pt \hrule height 4pt width \hsize \vskip4pt
33 \writetocentry{part}{#2}{#1}
36 \writetocentry{blankpart}{}{}
38 % Part TOC-entry definition for summary contents.
39 \gdef\dosmallpartentry#1#2#3#4{%
40 \vskip .5\baselineskip plus.2\baselineskip
43 \tocentry{Part #2: #1}{\doshortpageno\bgroup#4\egroup}
46 \gdef\dosmallblankpartentry#1#2#3#4{%
47 \vskip .5\baselineskip plus.2\baselineskip
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
52 \gdef\dopartentry#1#2#3#4{%
53 \unnchapentry{Part #2: #1}{}{#3}{#4}
55 \gdef\doblankpartentry#1#2#3#4{}
60 @c Use with @@smallbook.
62 @c %** start of document
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.
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
72 @c (To provide the reverse effect, set bindingoffset to -0.75in.)
75 @c \global\bindingoffset=0.75in
76 @c \global\normaloffset =0.75in
80 Copyright @copyright{} @value{copyrights-gfortran} Free Software Foundation, Inc.
82 Permission is granted to copy, distribute and/or modify this document
83 under the terms of the GNU Free Documentation License, Version 1.2 or
84 any later version published by the Free Software Foundation; with the
85 Invariant Sections being ``Funding Free Software'', the Front-Cover
86 Texts 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''.
90 (a) The FSF's Front-Cover Text is:
94 (b) The FSF's Back-Cover Text is:
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.
102 @dircategory Software development
104 * gfortran: (gfortran). The GNU Fortran Compiler.
106 This file documents the use and the internals of
107 the GNU Fortran compiler, (@command{gfortran}).
109 Published by the Free Software Foundation
110 51 Franklin Street, Fifth Floor
111 Boston, MA 02110-1301 USA
117 @setchapternewpage odd
119 @title Using GNU Fortran
121 @author The @t{gfortran} team
123 @vskip 0pt plus 1filll
124 Published by the Free Software Foundation@*
125 51 Franklin Street, Fifth Floor@*
126 Boston, MA 02110-1301, USA@*
127 @c Last printed ??ber, 19??.@*
128 @c Printed copies are available for $? each.@*
134 @c TODO: The following "Part" definitions are included here temporarily
135 @c until they are incorporated into the official Texinfo distribution.
138 \global\let\partentry=\dosmallpartentry
139 \global\let\blankpartentry=\dosmallblankpartentry
144 \global\let\partentry=\dopartentry
145 \global\let\blankpartentry=\doblankpartentry
151 @c ---------------------------------------------------------------------
152 @c TexInfo table of contents.
153 @c ---------------------------------------------------------------------
160 This manual documents the use of @command{gfortran},
161 the GNU Fortran compiler. You can find in this manual how to invoke
162 @command{gfortran}, as well as its features and incompatibilities.
165 @emph{Warning:} This document, and the compiler it describes, are still
166 under development. While efforts are made to keep it up-to-date, it might
167 not accurately reflect the status of the most recent GNU Fortran compiler.
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.
178 Part I: Invoking GNU Fortran
179 * Invoking GNU Fortran:: Command options supported by @command{gfortran}.
180 * Runtime:: Influencing runtime behavior with environment variables.
182 Part II: Language Reference
183 * Fortran 2003 and 2008 status:: Fortran 2003 and 2008 features supported by GNU Fortran.
184 * Compiler Characteristics:: KIND type parameters supported.
185 * Mixed-Language Programming:: Interoperability with C
186 * Extensions:: Language extensions implemented by GNU Fortran.
187 * Intrinsic Procedures:: Intrinsic procedures supported by GNU Fortran.
188 * Intrinsic Modules:: Intrinsic modules supported by GNU Fortran.
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
201 @c ---------------------------------------------------------------------
203 @c ---------------------------------------------------------------------
206 @chapter Introduction
208 @c The following duplicates the text on the TexInfo table of contents.
210 This manual documents the use of @command{gfortran}, the GNU Fortran
211 compiler. You can find in this manual how to invoke @command{gfortran},
212 as well as its features and incompatibilities.
215 @emph{Warning:} This document, and the compiler it describes, are still
216 under development. While efforts are made to keep it up-to-date, it
217 might not accurately reflect the status of the most recent GNU Fortran
222 The GNU Fortran compiler front end was
223 designed initially as a free replacement for,
224 or alternative to, the unix @command{f95} command;
225 @command{gfortran} is the command you'll use to invoke the compiler.
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.
237 @c ---------------------------------------------------------------------
239 @c ---------------------------------------------------------------------
241 @node About GNU Fortran
242 @section About GNU Fortran
244 The GNU Fortran compiler supports the Fortran 77, 90 and 95 standards
245 completely, parts of the Fortran 2003 and Fortran 2008 standards, and
246 several vendor extensions. The development goal is to provide the
251 Read a user's program,
252 stored in a file and containing instructions written
253 in Fortran 77, Fortran 90, Fortran 95, Fortran 2003 or Fortran 2008.
254 This file contains @dfn{source code}.
257 Translate the user's program into instructions a computer
258 can carry out more quickly than it takes to translate the
259 instructions in the first
260 place. The result after compilation of a program is
262 code designed to be efficiently translated and processed
263 by a machine such as your computer.
264 Humans usually aren't as good writing machine code
265 as they are at writing Fortran (or C++, Ada, or Java),
266 because it is easy to make tiny mistakes writing machine code.
269 Provide the user with information about the reasons why
270 the compiler is unable to create a binary from the source code.
271 Usually this will be the case if the source code is flawed.
272 The Fortran 90 standard requires that the compiler can point out
273 mistakes to the user.
274 An incorrect usage of the language causes an @dfn{error message}.
276 The compiler will also attempt to diagnose cases where the
277 user's program contains a correct usage of the language,
278 but instructs the computer to do something questionable.
279 This kind of diagnostics message is called a @dfn{warning message}.
282 Provide optional information about the translation passes
283 from the source code to machine code.
284 This can help a user of the compiler to find the cause of
285 certain bugs which may not be obvious in the source code,
286 but may be more easily found at a lower level compiler output.
287 It also helps developers to find bugs in the compiler itself.
290 Provide information in the generated machine code that can
291 make it easier to find bugs in the program (using a debugging tool,
292 called a @dfn{debugger}, such as the GNU Debugger @command{gdb}).
295 Locate and gather machine code already generated to
296 perform actions requested by statements in the user's program.
297 This machine code is organized into @dfn{modules} and is located
298 and @dfn{linked} to the user program.
301 The GNU Fortran compiler consists of several components:
305 A version of the @command{gcc} command
306 (which also might be installed as the system's @command{cc} command)
307 that also understands and accepts Fortran source code.
308 The @command{gcc} command is the @dfn{driver} program for
309 all the languages in the GNU Compiler Collection (GCC);
311 you can compile the source code of any language for
312 which a front end is available in GCC.
315 The @command{gfortran} command itself,
316 which also might be installed as the
317 system's @command{f95} command.
318 @command{gfortran} is just another driver program,
319 but specifically for the Fortran compiler only.
320 The difference with @command{gcc} is that @command{gfortran}
321 will automatically link the correct libraries to your program.
324 A collection of run-time libraries.
325 These libraries contain the machine code needed to support
326 capabilities of the Fortran language that are not directly
327 provided by the machine code generated by the
328 @command{gfortran} compilation phase,
329 such as intrinsic functions and subroutines,
330 and routines for interaction with files and the operating system.
331 @c and mechanisms to spawn,
332 @c unleash and pause threads in parallelized code.
335 The Fortran compiler itself, (@command{f951}).
336 This is the GNU Fortran parser and code generator,
337 linked to and interfaced with the GCC backend library.
338 @command{f951} ``translates'' the source code to
339 assembler code. You would typically not use this
341 instead, the @command{gcc} or @command{gfortran} driver
342 programs will call it for you.
346 @c ---------------------------------------------------------------------
347 @c GNU Fortran and GCC
348 @c ---------------------------------------------------------------------
350 @node GNU Fortran and GCC
351 @section GNU Fortran and GCC
352 @cindex GNU Compiler Collection
355 GNU Fortran is a part of GCC, the @dfn{GNU Compiler Collection}. GCC
356 consists of a collection of front ends for various languages, which
357 translate the source code into a language-independent form called
358 @dfn{GENERIC}. This is then processed by a common middle end which
359 provides optimization, and then passed to one of a collection of back
360 ends which generate code for different computer architectures and
363 Functionally, this is implemented with a driver program (@command{gcc})
364 which provides the command-line interface for the compiler. It calls
365 the relevant compiler front-end program (e.g., @command{f951} for
366 Fortran) for each file in the source code, and then calls the assembler
367 and linker as appropriate to produce the compiled output. In a copy of
368 GCC 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
371 Fortran source code, and compile it accordingly. A @command{gfortran}
372 driver program is also provided, which is identical to @command{gcc}
373 except that it automatically links the Fortran runtime libraries into the
376 Source 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.
378 Source files with @file{.f90}, @file{.f95}, @file{.f03}, @file{.f08},
379 @file{.F90}, @file{.F95}, @file{.F03} and @file{.F08} extensions are
380 treated as free form. The capitalized versions of either form are run
381 through preprocessing. Source files with the lower case @file{.fpp}
382 extension are also run through preprocessing.
384 This manual specifically documents the Fortran front end, which handles
385 the programming language's syntax and semantics. The aspects of GCC
386 which relate to the optimization passes and the back-end code generation
387 are documented in the GCC manual; see
388 @ref{Top,,Introduction,gcc,Using the GNU Compiler Collection (GCC)}.
389 The two manuals together provide a complete reference for the GNU
393 @c ---------------------------------------------------------------------
394 @c Preprocessing and conditional compilation
395 @c ---------------------------------------------------------------------
397 @node Preprocessing and conditional compilation
398 @section Preprocessing and conditional compilation
401 @cindex Conditional compilation
402 @cindex Preprocessing
403 @cindex preprocessor, include file handling
405 Many Fortran compilers including GNU Fortran allow passing the source code
406 through a C preprocessor (CPP; sometimes also called the Fortran preprocessor,
407 FPP) to allow for conditional compilation. In the case of GNU Fortran,
408 this is the GNU C Preprocessor in the traditional mode. On systems with
409 case-preserving file names, the preprocessor is automatically invoked if the
410 filename extension is @code{.F}, @code{.FOR}, @code{.FTN}, @code{.fpp},
411 @code{.FPP}, @code{.F90}, @code{.F95}, @code{.F03} or @code{.F08}. To manually
412 invoke the preprocessor on any file, use @option{-cpp}, to disable
413 preprocessing on files where the preprocessor is run automatically, use
416 If a preprocessed file includes another file with the Fortran @code{INCLUDE}
417 statement, the included file is not preprocessed. To preprocess included
418 files, use the equivalent preprocessor statement @code{#include}.
420 If GNU Fortran invokes the preprocessor, @code{__GFORTRAN__}
421 is defined and @code{__GNUC__}, @code{__GNUC_MINOR__} and
422 @code{__GNUC_PATCHLEVEL__} can be used to determine the version of the
423 compiler. See @ref{Top,,Overview,cpp,The C Preprocessor} for details.
425 While CPP is the de-facto standard for preprocessing Fortran code,
426 Part 3 of the Fortran 95 standard (ISO/IEC 1539-3:1998) defines
427 Conditional Compilation, which is not widely used and not directly
428 supported by the GNU Fortran compiler. You can use the program coco
429 to preprocess such files (@uref{http://users.erols.com/dnagle/coco.html}).
432 @c ---------------------------------------------------------------------
433 @c GNU Fortran and G77
434 @c ---------------------------------------------------------------------
436 @node GNU Fortran and G77
437 @section GNU Fortran and G77
439 @cindex @command{g77}
441 The GNU Fortran compiler is the successor to @command{g77}, the Fortran
442 77 front end included in GCC prior to version 4. It is an entirely new
443 program that has been designed to provide Fortran 95 support and
444 extensibility for future Fortran language standards, as well as providing
445 backwards compatibility for Fortran 77 and nearly all of the GNU language
446 extensions supported by @command{g77}.
449 @c ---------------------------------------------------------------------
451 @c ---------------------------------------------------------------------
454 @section Project Status
457 As soon as @command{gfortran} can parse all of the statements correctly,
458 it will be in the ``larva'' state.
459 When we generate code, the ``puppa'' state.
460 When @command{gfortran} is done,
461 we'll see if it will be a beautiful butterfly,
462 or just a big bug....
464 --Andy Vaught, April 2000
467 The start of the GNU Fortran 95 project was announced on
468 the GCC homepage in March 18, 2000
469 (even though Andy had already been working on it for a while,
472 The GNU Fortran compiler is able to compile nearly all
473 standard-compliant Fortran 95, Fortran 90, and Fortran 77 programs,
474 including a number of standard and non-standard extensions, and can be
475 used on real-world programs. In particular, the supported extensions
476 include OpenMP, Cray-style pointers, and several Fortran 2003 and Fortran
477 2008 features such as enumeration, stream I/O, and some of the
478 enhancements to allocatable array support from TR 15581. However, it is
479 still under development and has a few remaining rough edges.
481 At present, the GNU Fortran compiler passes the
482 @uref{http://www.fortran-2000.com/ArnaudRecipes/fcvs21_f95.html,
483 NIST Fortran 77 Test Suite}, and produces acceptable results on the
484 @uref{http://www.netlib.org/lapack/faq.html#1.21, LAPACK Test Suite}.
485 It also provides respectable performance on
486 the @uref{http://www.polyhedron.com/pb05.html, Polyhedron Fortran
487 compiler benchmarks} and the
488 @uref{http://www.llnl.gov/asci_benchmarks/asci/limited/lfk/README.html,
489 Livermore Fortran Kernels test}. It has been used to compile a number of
490 large real-world programs, including
491 @uref{http://mysite.verizon.net/serveall/moene.pdf, the HIRLAM
492 weather-forecasting code} and
493 @uref{http://www.theochem.uwa.edu.au/tonto/, the Tonto quantum
494 chemistry package}; see @url{http://gcc.gnu.org/wiki/GfortranApps} for an
497 Among other things, the GNU Fortran compiler is intended as a replacement
498 for G77. At this point, nearly all programs that could be compiled with
499 G77 can be compiled with GNU Fortran, although there are a few minor known
502 The primary work remaining to be done on GNU Fortran falls into three
503 categories: bug fixing (primarily regarding the treatment of invalid code
504 and providing useful error messages), improving the compiler optimizations
505 and the performance of compiled code, and extending the compiler to support
506 future standards---in particular, Fortran 2003 and Fortran 2008.
509 @c ---------------------------------------------------------------------
511 @c ---------------------------------------------------------------------
518 * Varying Length Character Strings::
521 The GNU Fortran compiler implements
522 ISO/IEC 1539:1997 (Fortran 95). As such, it can also compile essentially all
523 standard-compliant Fortran 90 and Fortran 77 programs. It also supports
524 the ISO/IEC TR-15581 enhancements to allocatable arrays, and
525 the @uref{http://www.openmp.org/drupal/mp-documents/spec25.pdf,
526 OpenMP Application Program Interface v2.5} specification.
528 In the future, the GNU Fortran compiler will also support ISO/IEC
529 1539-1:2004 (Fortran 2003) and future Fortran standards. Partial support
530 of that standard is already provided; the current status of Fortran 2003
531 support is reported in the @ref{Fortran 2003 status} section of the
534 The next version of the Fortran standard (Fortran 2008) is currently
535 being developed and the GNU Fortran compiler supports some of its new
536 features. This support is based on the latest draft of the standard
537 (available from @url{http://www.nag.co.uk/sc22wg5/}) and no guarantee of
538 future compatibility is made, as the final standard might differ from the
539 draft. For more information, see the @ref{Fortran 2008 status} section.
541 Additionally, the GNU Fortran compilers supports the OpenMP specification
542 (version 3.0, @url{http://openmp.org/wp/openmp-specifications/}).
544 @node Varying Length Character Strings
545 @subsection Varying Length Character Strings
546 @cindex Varying length character strings
547 @cindex Varying length strings
548 @cindex strings, varying length
550 The Fortran 95 standard specifies in Part 2 (ISO/IEC 1539-2:2000)
551 varying length character strings. While GNU Fortran currently does not
552 support such strings directly, there exist two Fortran implementations
553 for them, which work with GNU Fortran. They can be found at
554 @uref{http://www.fortran.com/@/iso_varying_string.f95} and at
555 @uref{ftp://ftp.nag.co.uk/@/sc22wg5/@/ISO_VARYING_STRING/}.
559 @c =====================================================================
560 @c PART I: INVOCATION REFERENCE
561 @c =====================================================================
564 \part{I}{Invoking GNU Fortran}
567 @c ---------------------------------------------------------------------
569 @c ---------------------------------------------------------------------
574 @c ---------------------------------------------------------------------
576 @c ---------------------------------------------------------------------
579 @chapter Runtime: Influencing runtime behavior with environment variables
580 @cindex environment variable
582 The behavior of the @command{gfortran} can be influenced by
583 environment variables.
585 Malformed environment variables are silently ignored.
588 * GFORTRAN_STDIN_UNIT:: Unit number for standard input
589 * GFORTRAN_STDOUT_UNIT:: Unit number for standard output
590 * GFORTRAN_STDERR_UNIT:: Unit number for standard error
591 * GFORTRAN_USE_STDERR:: Send library output to standard error
592 * GFORTRAN_TMPDIR:: Directory for scratch files
593 * GFORTRAN_UNBUFFERED_ALL:: Don't buffer I/O for all units.
594 * GFORTRAN_UNBUFFERED_PRECONNECTED:: Don't buffer I/O for preconnected units.
595 * GFORTRAN_SHOW_LOCUS:: Show location for runtime errors
596 * GFORTRAN_OPTIONAL_PLUS:: Print leading + where permitted
597 * GFORTRAN_DEFAULT_RECL:: Default record length for new files
598 * GFORTRAN_LIST_SEPARATOR:: Separator for list output
599 * GFORTRAN_CONVERT_UNIT:: Set endianness for unformatted I/O
600 * GFORTRAN_ERROR_DUMPCORE:: Dump core on run-time errors
601 * GFORTRAN_ERROR_BACKTRACE:: Show backtrace on run-time errors
604 @node GFORTRAN_STDIN_UNIT
605 @section @env{GFORTRAN_STDIN_UNIT}---Unit number for standard input
607 This environment variable can be used to select the unit number
608 preconnected to standard input. This must be a positive integer.
609 The default value is 5.
611 @node GFORTRAN_STDOUT_UNIT
612 @section @env{GFORTRAN_STDOUT_UNIT}---Unit number for standard output
614 This environment variable can be used to select the unit number
615 preconnected to standard output. This must be a positive integer.
616 The default value is 6.
618 @node GFORTRAN_STDERR_UNIT
619 @section @env{GFORTRAN_STDERR_UNIT}---Unit number for standard error
621 This environment variable can be used to select the unit number
622 preconnected to standard error. This must be a positive integer.
623 The default value is 0.
625 @node GFORTRAN_USE_STDERR
626 @section @env{GFORTRAN_USE_STDERR}---Send library output to standard error
628 This environment variable controls where library output is sent.
629 If the first letter is @samp{y}, @samp{Y} or @samp{1}, standard
630 error is used. If the first letter is @samp{n}, @samp{N} or
631 @samp{0}, standard output is used.
633 @node GFORTRAN_TMPDIR
634 @section @env{GFORTRAN_TMPDIR}---Directory for scratch files
636 This environment variable controls where scratch files are
637 created. If this environment variable is missing,
638 GNU Fortran searches for the environment variable @env{TMP}. If
639 this is also missing, the default is @file{/tmp}.
641 @node GFORTRAN_UNBUFFERED_ALL
642 @section @env{GFORTRAN_UNBUFFERED_ALL}---Don't buffer I/O on all units
644 This environment variable controls whether all I/O is unbuffered. If
645 the first letter is @samp{y}, @samp{Y} or @samp{1}, all I/O is
646 unbuffered. This will slow down small sequential reads and writes. If
647 the first letter is @samp{n}, @samp{N} or @samp{0}, I/O is buffered.
650 @node GFORTRAN_UNBUFFERED_PRECONNECTED
651 @section @env{GFORTRAN_UNBUFFERED_PRECONNECTED}---Don't buffer I/O on preconnected units
653 The environment variable named @env{GFORTRAN_UNBUFFERED_PRECONNECTED} controls
654 whether I/O on a preconnected unit (i.e.@: STDOUT or STDERR) is unbuffered. If
655 the first letter is @samp{y}, @samp{Y} or @samp{1}, I/O is unbuffered. This
656 will slow down small sequential reads and writes. If the first letter
657 is @samp{n}, @samp{N} or @samp{0}, I/O is buffered. This is the default.
659 @node GFORTRAN_SHOW_LOCUS
660 @section @env{GFORTRAN_SHOW_LOCUS}---Show location for runtime errors
662 If the first letter is @samp{y}, @samp{Y} or @samp{1}, filename and
663 line numbers for runtime errors are printed. If the first letter is
664 @samp{n}, @samp{N} or @samp{0}, don't print filename and line numbers
665 for runtime errors. The default is to print the location.
667 @node GFORTRAN_OPTIONAL_PLUS
668 @section @env{GFORTRAN_OPTIONAL_PLUS}---Print leading + where permitted
670 If the first letter is @samp{y}, @samp{Y} or @samp{1},
671 a plus sign is printed
672 where permitted by the Fortran standard. If the first letter
673 is @samp{n}, @samp{N} or @samp{0}, a plus sign is not printed
674 in most cases. Default is not to print plus signs.
676 @node GFORTRAN_DEFAULT_RECL
677 @section @env{GFORTRAN_DEFAULT_RECL}---Default record length for new files
679 This environment variable specifies the default record length, in
680 bytes, for files which are opened without a @code{RECL} tag in the
681 @code{OPEN} statement. This must be a positive integer. The
682 default value is 1073741824 bytes (1 GB).
684 @node GFORTRAN_LIST_SEPARATOR
685 @section @env{GFORTRAN_LIST_SEPARATOR}---Separator for list output
687 This environment variable specifies the separator when writing
688 list-directed output. It may contain any number of spaces and
689 at most one comma. If you specify this on the command line,
690 be sure to quote spaces, as in
692 $ GFORTRAN_LIST_SEPARATOR=' , ' ./a.out
694 when @command{a.out} is the compiled Fortran program that you want to run.
695 Default is a single space.
697 @node GFORTRAN_CONVERT_UNIT
698 @section @env{GFORTRAN_CONVERT_UNIT}---Set endianness for unformatted I/O
700 By setting the @env{GFORTRAN_CONVERT_UNIT} variable, it is possible
701 to change the representation of data for unformatted files.
702 The syntax for the @env{GFORTRAN_CONVERT_UNIT} variable is:
704 GFORTRAN_CONVERT_UNIT: mode | mode ';' exception | exception ;
705 mode: 'native' | 'swap' | 'big_endian' | 'little_endian' ;
706 exception: mode ':' unit_list | unit_list ;
707 unit_list: unit_spec | unit_list unit_spec ;
708 unit_spec: INTEGER | INTEGER '-' INTEGER ;
710 The variable consists of an optional default mode, followed by
711 a list of optional exceptions, which are separated by semicolons
712 from the preceding default and each other. Each exception consists
713 of a format and a comma-separated list of units. Valid values for
714 the modes are the same as for the @code{CONVERT} specifier:
717 @item @code{NATIVE} Use the native format. This is the default.
718 @item @code{SWAP} Swap between little- and big-endian.
719 @item @code{LITTLE_ENDIAN} Use the little-endian format
720 for unformatted files.
721 @item @code{BIG_ENDIAN} Use the big-endian format for unformatted files.
723 A missing mode for an exception is taken to mean @code{BIG_ENDIAN}.
724 Examples of values for @env{GFORTRAN_CONVERT_UNIT} are:
726 @item @code{'big_endian'} Do all unformatted I/O in big_endian mode.
727 @item @code{'little_endian;native:10-20,25'} Do all unformatted I/O
728 in little_endian mode, except for units 10 to 20 and 25, which are in
730 @item @code{'10-20'} Units 10 to 20 are big-endian, the rest is native.
733 Setting the environment variables should be done on the command
734 line or via the @command{export}
735 command for @command{sh}-compatible shells and via @command{setenv}
736 for @command{csh}-compatible shells.
738 Example for @command{sh}:
741 $ GFORTRAN_CONVERT_UNIT='big_endian;native:10-20' ./a.out
744 Example code for @command{csh}:
747 % setenv GFORTRAN_CONVERT_UNIT 'big_endian;native:10-20'
751 Using anything but the native representation for unformatted data
752 carries a significant speed overhead. If speed in this area matters
753 to you, it is best if you use this only for data that needs to be
756 @xref{CONVERT specifier}, for an alternative way to specify the
757 data representation for unformatted files. @xref{Runtime Options}, for
758 setting a default data representation for the whole program. The
759 @code{CONVERT} specifier overrides the @option{-fconvert} compile options.
761 @emph{Note that the values specified via the GFORTRAN_CONVERT_UNIT
762 environment variable will override the CONVERT specifier in the
763 open statement}. This is to give control over data formats to
764 users who do not have the source code of their program available.
766 @node GFORTRAN_ERROR_DUMPCORE
767 @section @env{GFORTRAN_ERROR_DUMPCORE}---Dump core on run-time errors
769 If the @env{GFORTRAN_ERROR_DUMPCORE} variable is set to
770 @samp{y}, @samp{Y} or @samp{1} (only the first letter is relevant)
771 then library run-time errors cause core dumps. To disable the core
772 dumps, set the variable to @samp{n}, @samp{N}, @samp{0}. Default
773 is not to core dump unless the @option{-fdump-core} compile option
776 @node GFORTRAN_ERROR_BACKTRACE
777 @section @env{GFORTRAN_ERROR_BACKTRACE}---Show backtrace on run-time errors
779 If the @env{GFORTRAN_ERROR_BACKTRACE} variable is set to
780 @samp{y}, @samp{Y} or @samp{1} (only the first letter is relevant)
781 then a backtrace is printed when a run-time error occurs.
782 To disable the backtracing, set the variable to
783 @samp{n}, @samp{N}, @samp{0}. Default is not to print a backtrace
784 unless the @option{-fbacktrace} compile option
787 @c =====================================================================
788 @c PART II: LANGUAGE REFERENCE
789 @c =====================================================================
792 \part{II}{Language Reference}
795 @c ---------------------------------------------------------------------
796 @c Fortran 2003 and 2008 Status
797 @c ---------------------------------------------------------------------
799 @node Fortran 2003 and 2008 status
800 @chapter Fortran 2003 and 2008 Status
803 * Fortran 2003 status::
804 * Fortran 2008 status::
807 @node Fortran 2003 status
808 @section Fortran 2003 status
810 GNU Fortran supports several Fortran 2003 features; an incomplete
811 list can be found below.
815 Intrinsics @code{command_argument_count}, @code{get_command},
816 @code{get_command_argument}, @code{get_environment_variable}, and
820 @cindex array, constructors
822 Array constructors using square brackets. That is, @code{[...]} rather
826 @cindex @code{FLUSH} statement
827 @cindex statement, @code{FLUSH}
828 @code{FLUSH} statement.
831 @cindex @code{IOMSG=} specifier
832 @code{IOMSG=} specifier for I/O statements.
835 @cindex @code{ENUM} statement
836 @cindex @code{ENUMERATOR} statement
837 @cindex statement, @code{ENUM}
838 @cindex statement, @code{ENUMERATOR}
839 @opindex @code{fshort-enums}
840 Support for the declaration of enumeration constants via the
841 @code{ENUM} and @code{ENUMERATOR} statements. Interoperability with
842 @command{gcc} is guaranteed also for the case where the
843 @command{-fshort-enums} command line option is given.
850 @cindex @code{ALLOCATABLE} dummy arguments
851 @code{ALLOCATABLE} dummy arguments.
853 @cindex @code{ALLOCATABLE} function results
854 @code{ALLOCATABLE} function results
856 @cindex @code{ALLOCATABLE} components of derived types
857 @code{ALLOCATABLE} components of derived types
861 @cindex @code{STREAM} I/O
862 @cindex @code{ACCESS='STREAM'} I/O
863 The @code{OPEN} statement supports the @code{ACCESS='STREAM'} specifier,
864 allowing I/O without any record structure.
867 Namelist input/output for internal files.
870 @cindex @code{PROTECTED} statement
871 @cindex statement, @code{PROTECTED}
872 The @code{PROTECTED} statement and attribute.
875 @cindex @code{VALUE} statement
876 @cindex statement, @code{VALUE}
877 The @code{VALUE} statement and attribute.
880 @cindex @code{VOLATILE} statement
881 @cindex statement, @code{VOLATILE}
882 The @code{VOLATILE} statement and attribute.
885 @cindex @code{IMPORT} statement
886 @cindex statement, @code{IMPORT}
887 The @code{IMPORT} statement, allowing to import
888 host-associated derived types.
891 @cindex @code{USE, INTRINSIC} statement
892 @cindex statement, @code{USE, INTRINSIC}
893 @cindex @code{ISO_FORTRAN_ENV} statement
894 @cindex statement, @code{ISO_FORTRAN_ENV}
895 @code{USE} statement with @code{INTRINSIC} and @code{NON_INTRINSIC}
896 attribute; supported intrinsic modules: @code{ISO_FORTRAN_ENV},
897 @code{OMP_LIB} and @code{OMP_LIB_KINDS}.
900 Renaming of operators in the @code{USE} statement.
903 @cindex ISO C Bindings
904 Interoperability with C (ISO C Bindings)
907 BOZ as argument of INT, REAL, DBLE and CMPLX.
912 @node Fortran 2008 status
913 @section Fortran 2008 status
915 The next version of the Fortran standard after Fortran 2003 is currently
916 being worked on by the Working Group 5 of Sub-Committee 22 of the Joint
917 Technical Committee 1 of the International Organization for
918 Standardization (ISO) and the International Electrotechnical Commission
919 (IEC). This group is known at @uref{http://www.nag.co.uk/sc22wg5/, WG5}.
920 The next revision of the Fortran standard is informally referred to as
921 Fortran 2008, reflecting its planned release year. The GNU Fortran
922 compiler has support for some of the new features in Fortran 2008. This
923 support is based on the latest draft, available from
924 @url{http://www.nag.co.uk/sc22wg5/}. However, as the final standard may
925 differ from the drafts, no guarantee of backward compatibility can be
926 made and you should only use it for experimental purposes.
929 @c ---------------------------------------------------------------------
930 @c Compiler Characteristics
931 @c ---------------------------------------------------------------------
933 @node Compiler Characteristics
934 @chapter Compiler Characteristics
936 @c TODO: Formulate this introduction a little more generally once
937 @c there is more here than KIND type parameters.
939 This chapter describes certain characteristics of the GNU Fortran compiler,
940 namely the KIND type parameter values supported.
943 * KIND Type Parameters::
947 @node KIND Type Parameters
948 @section KIND Type Parameters
951 The @code{KIND} type parameters supported by GNU Fortran for the primitive
957 1, 2, 4, 8*, 16*, default: 4 (1)
960 1, 2, 4, 8*, 16*, default: 4 (1)
963 4, 8, 10**, 16**, default: 4 (2)
966 4, 8, 10**, 16**, default: 4 (2)
974 * = not available on all systems @*
975 ** = not available on all systems; additionally 10 and 16 are never
976 available at the same time @*
977 (1) Unless -fdefault-integer-8 is used @*
978 (2) Unless -fdefault-real-8 is used
981 The @code{KIND} value matches the storage size in bytes, except for
982 @code{COMPLEX} where the storage size is twice as much (or both real and
983 imaginary part are a real value of the given size). It is recommended to use
984 the @code{SELECT_*_KIND} intrinsics instead of the concrete values.
987 @c ---------------------------------------------------------------------
989 @c ---------------------------------------------------------------------
991 @c Maybe this chapter should be merged with the 'Standards' section,
992 @c whenever that is written :-)
998 The two sections below detail the extensions to standard Fortran that are
999 implemented in GNU Fortran, as well as some of the popular or
1000 historically important extensions that are not (or not yet) implemented.
1001 For the latter case, we explain the alternatives available to GNU Fortran
1002 users, including replacement by standard-conforming code or GNU
1006 * Extensions implemented in GNU Fortran::
1007 * Extensions not implemented in GNU Fortran::
1011 @node Extensions implemented in GNU Fortran
1012 @section Extensions implemented in GNU Fortran
1013 @cindex extensions, implemented
1015 GNU Fortran implements a number of extensions over standard
1016 Fortran. This chapter contains information on their syntax and
1017 meaning. There are currently two categories of GNU Fortran
1018 extensions, those that provide functionality beyond that provided
1019 by any standard, and those that are supported by GNU Fortran
1020 purely for backward compatibility with legacy compilers. By default,
1021 @option{-std=gnu} allows the compiler to accept both types of
1022 extensions, but to warn about the use of the latter. Specifying
1023 either @option{-std=f95}, @option{-std=f2003} or @option{-std=f2008}
1024 disables both types of extensions, and @option{-std=legacy} allows both
1028 * Old-style kind specifications::
1029 * Old-style variable initialization::
1030 * Extensions to namelist::
1031 * X format descriptor without count field::
1032 * Commas in FORMAT specifications::
1033 * Missing period in FORMAT specifications::
1035 * BOZ literal constants::
1036 * Real array indices::
1038 * Implicitly convert LOGICAL and INTEGER values::
1039 * Hollerith constants support::
1041 * CONVERT specifier::
1043 * Argument list functions::
1046 @node Old-style kind specifications
1047 @subsection Old-style kind specifications
1048 @cindex kind, old-style
1050 GNU Fortran allows old-style kind specifications in declarations. These
1056 where @code{TYPESPEC} is a basic type (@code{INTEGER}, @code{REAL},
1057 etc.), and where @code{size} is a byte count corresponding to the
1058 storage size of a valid kind for that type. (For @code{COMPLEX}
1059 variables, @code{size} is the total size of the real and imaginary
1060 parts.) The statement then declares @code{x}, @code{y} and @code{z} to
1061 be of type @code{TYPESPEC} with the appropriate kind. This is
1062 equivalent to the standard-conforming declaration
1067 where @code{k} is the kind parameter suitable for the intended precision. As
1068 kind parameters are implementation-dependent, use the @code{KIND},
1069 @code{SELECTED_INT_KIND} and @code{SELECTED_REAL_KIND} intrinsics to retrieve
1070 the correct value, for instance @code{REAL*8 x} can be replaced by:
1072 INTEGER, PARAMETER :: dbl = KIND(1.0d0)
1076 @node Old-style variable initialization
1077 @subsection Old-style variable initialization
1079 GNU Fortran allows old-style initialization of variables of the
1083 REAL x(2,2) /3*0.,1./
1085 The syntax for the initializers is as for the @code{DATA} statement, but
1086 unlike in a @code{DATA} statement, an initializer only applies to the
1087 variable immediately preceding the initialization. In other words,
1088 something like @code{INTEGER I,J/2,3/} is not valid. This style of
1089 initialization is only allowed in declarations without double colons
1090 (@code{::}); the double colons were introduced in Fortran 90, which also
1091 introduced a standard syntax for initializing variables in type
1094 Examples of standard-conforming code equivalent to the above example
1098 INTEGER :: i = 1, j = 2
1099 REAL :: x(2,2) = RESHAPE((/0.,0.,0.,1./),SHAPE(x))
1103 DATA i/1/, j/2/, x/3*0.,1./
1106 Note that variables which are explicitly initialized in declarations
1107 or in @code{DATA} statements automatically acquire the @code{SAVE}
1110 @node Extensions to namelist
1111 @subsection Extensions to namelist
1114 GNU Fortran fully supports the Fortran 95 standard for namelist I/O
1115 including array qualifiers, substrings and fully qualified derived types.
1116 The output from a namelist write is compatible with namelist read. The
1117 output has all names in upper case and indentation to column 1 after the
1118 namelist name. Two extensions are permitted:
1120 Old-style use of @samp{$} instead of @samp{&}
1123 X(:)%Y(2) = 1.0 2.0 3.0
1128 It should be noted that the default terminator is @samp{/} rather than
1131 Querying of the namelist when inputting from stdin. After at least
1132 one space, entering @samp{?} sends to stdout the namelist name and the names of
1133 the variables in the namelist:
1144 Entering @samp{=?} outputs the namelist to stdout, as if
1145 @code{WRITE(*,NML = mynml)} had been called:
1150 X(1)%Y= 0.000000 , 1.000000 , 0.000000 ,
1151 X(2)%Y= 0.000000 , 2.000000 , 0.000000 ,
1152 X(3)%Y= 0.000000 , 3.000000 , 0.000000 ,
1156 To aid this dialog, when input is from stdin, errors send their
1157 messages to stderr and execution continues, even if @code{IOSTAT} is set.
1159 @code{PRINT} namelist is permitted. This causes an error if
1160 @option{-std=f95} is used.
1163 REAL, dimension (4) :: x = (/1.0, 2.0, 3.0, 4.0/)
1166 END PROGRAM test_print
1169 Expanded namelist reads are permitted. This causes an error if
1170 @option{-std=f95} is used. In the following example, the first element
1171 of the array will be given the value 0.00 and the two succeeding
1172 elements will be given the values 1.00 and 2.00.
1175 X(1,1) = 0.00 , 1.00 , 2.00
1179 @node X format descriptor without count field
1180 @subsection @code{X} format descriptor without count field
1182 To support legacy codes, GNU Fortran permits the count field of the
1183 @code{X} edit descriptor in @code{FORMAT} statements to be omitted.
1184 When omitted, the count is implicitly assumed to be one.
1188 10 FORMAT (I1, X, I1)
1191 @node Commas in FORMAT specifications
1192 @subsection Commas in @code{FORMAT} specifications
1194 To support legacy codes, GNU Fortran allows the comma separator
1195 to be omitted immediately before and after character string edit
1196 descriptors in @code{FORMAT} statements.
1200 10 FORMAT ('FOO='I1' BAR='I2)
1204 @node Missing period in FORMAT specifications
1205 @subsection Missing period in @code{FORMAT} specifications
1207 To support legacy codes, GNU Fortran allows missing periods in format
1208 specifications if and only if @option{-std=legacy} is given on the
1209 command line. This is considered non-conforming code and is
1218 @node I/O item lists
1219 @subsection I/O item lists
1220 @cindex I/O item lists
1222 To support legacy codes, GNU Fortran allows the input item list
1223 of the @code{READ} statement, and the output item lists of the
1224 @code{WRITE} and @code{PRINT} statements, to start with a comma.
1226 @node BOZ literal constants
1227 @subsection BOZ literal constants
1228 @cindex BOZ literal constants
1230 Besides decimal constants, Fortran also supports binary (@code{b}),
1231 octal (@code{o}) and hexadecimal (@code{z}) integer constants. The
1232 syntax is: @samp{prefix quote digits quote}, were the prefix is
1233 either @code{b}, @code{o} or @code{z}, quote is either @code{'} or
1234 @code{"} and the digits are for binary @code{0} or @code{1}, for
1235 octal between @code{0} and @code{7}, and for hexadecimal between
1236 @code{0} and @code{F}. (Example: @code{b'01011101'}.)
1238 Up to Fortran 95, BOZ literals were only allowed to initialize
1239 integer variables in DATA statements. Since Fortran 2003 BOZ literals
1240 are also allowed as argument of @code{REAL}, @code{DBLE}, @code{INT}
1241 and @code{CMPLX}; the result is the same as if the integer BOZ
1242 literal had been converted by @code{TRANSFER} to, respectively,
1243 @code{real}, @code{double precision}, @code{integer} or @code{complex}.
1244 As GNU Fortran extension the intrinsic procedures @code{FLOAT},
1245 @code{DFLOAT}, @code{COMPLEX} and @code{DCMPLX} are treated alike.
1247 As an extension, GNU Fortran allows hexadecimal BOZ literal constants to
1248 be specified using the @code{X} prefix, in addition to the standard
1249 @code{Z} prefix. The BOZ literal can also be specified by adding a
1250 suffix to the string, for example, @code{Z'ABC'} and @code{'ABC'Z} are
1253 Furthermore, GNU Fortran allows using BOZ literal constants outside
1254 DATA statements and the four intrinsic functions allowed by Fortran 2003.
1255 In DATA statements, in direct assignments, where the right-hand side
1256 only contains a BOZ literal constant, and for old-style initializers of
1257 the form @code{integer i /o'0173'/}, the constant is transferred
1258 as if @code{TRANSFER} had been used; for @code{COMPLEX} numbers, only
1259 the real part is initialized unless @code{CMPLX} is used. In all other
1260 cases, the BOZ literal constant is converted to an @code{INTEGER} value with
1261 the largest decimal representation. This value is then converted
1262 numerically to the type and kind of the variable in question.
1263 (For instance, @code{real :: r = b'0000001' + 1} initializes @code{r}
1264 with @code{2.0}.) As different compilers implement the extension
1265 differently, one should be careful when doing bitwise initialization
1266 of non-integer variables.
1268 Note that initializing an @code{INTEGER} variable with a statement such
1269 as @code{DATA i/Z'FFFFFFFF'/} will give an integer overflow error rather
1270 than the desired result of @math{-1} when @code{i} is a 32-bit integer
1271 on a system that supports 64-bit integers. The @samp{-fno-range-check}
1272 option can be used as a workaround for legacy code that initializes
1273 integers in this manner.
1275 @node Real array indices
1276 @subsection Real array indices
1277 @cindex array, indices of type real
1279 As an extension, GNU Fortran allows the use of @code{REAL} expressions
1280 or variables as array indices.
1282 @node Unary operators
1283 @subsection Unary operators
1284 @cindex operators, unary
1286 As an extension, GNU Fortran allows unary plus and unary minus operators
1287 to appear as the second operand of binary arithmetic operators without
1288 the need for parenthesis.
1294 @node Implicitly convert LOGICAL and INTEGER values
1295 @subsection Implicitly convert @code{LOGICAL} and @code{INTEGER} values
1296 @cindex conversion, to integer
1297 @cindex conversion, to logical
1299 As an extension for backwards compatibility with other compilers, GNU
1300 Fortran allows the implicit conversion of @code{LOGICAL} values to
1301 @code{INTEGER} values and vice versa. When converting from a
1302 @code{LOGICAL} to an @code{INTEGER}, @code{.FALSE.} is interpreted as
1303 zero, and @code{.TRUE.} is interpreted as one. When converting from
1304 @code{INTEGER} to @code{LOGICAL}, the value zero is interpreted as
1305 @code{.FALSE.} and any nonzero value is interpreted as @code{.TRUE.}.
1316 However, there is no implicit conversion of @code{INTEGER} values in
1317 @code{if}-statements, nor of @code{LOGICAL} or @code{INTEGER} values
1320 @node Hollerith constants support
1321 @subsection Hollerith constants support
1322 @cindex Hollerith constants
1324 GNU Fortran supports Hollerith constants in assignments, function
1325 arguments, and @code{DATA} and @code{ASSIGN} statements. A Hollerith
1326 constant is written as a string of characters preceded by an integer
1327 constant indicating the character count, and the letter @code{H} or
1328 @code{h}, and stored in bytewise fashion in a numeric (@code{INTEGER},
1329 @code{REAL}, or @code{complex}) or @code{LOGICAL} variable. The
1330 constant will be padded or truncated to fit the size of the variable in
1333 Examples of valid uses of Hollerith constants:
1336 data x /16Habcdefghijklmnop, 16Hqrstuvwxyz012345/
1337 x(1) = 16HABCDEFGHIJKLMNOP
1341 Invalid Hollerith constants examples:
1344 a = 8H12345678 ! Valid, but the Hollerith constant will be truncated.
1345 a = 0H ! At least one character is needed.
1348 In general, Hollerith constants were used to provide a rudimentary
1349 facility for handling character strings in early Fortran compilers,
1350 prior to the introduction of @code{CHARACTER} variables in Fortran 77;
1351 in those cases, the standard-compliant equivalent is to convert the
1352 program to use proper character strings. On occasion, there may be a
1353 case where the intent is specifically to initialize a numeric variable
1354 with a given byte sequence. In these cases, the same result can be
1355 obtained by using the @code{TRANSFER} statement, as in this example.
1357 INTEGER(KIND=4) :: a
1358 a = TRANSFER ("abcd", a) ! equivalent to: a = 4Habcd
1363 @subsection Cray pointers
1364 @cindex pointer, Cray
1366 Cray pointers are part of a non-standard extension that provides a
1367 C-like pointer in Fortran. This is accomplished through a pair of
1368 variables: an integer "pointer" that holds a memory address, and a
1369 "pointee" that is used to dereference the pointer.
1371 Pointer/pointee pairs are declared in statements of the form:
1373 pointer ( <pointer> , <pointee> )
1377 pointer ( <pointer1> , <pointee1> ), ( <pointer2> , <pointee2> ), ...
1379 The pointer is an integer that is intended to hold a memory address.
1380 The pointee may be an array or scalar. A pointee can be an assumed
1381 size array---that is, the last dimension may be left unspecified by
1382 using a @code{*} in place of a value---but a pointee cannot be an
1383 assumed shape array. No space is allocated for the pointee.
1385 The pointee may have its type declared before or after the pointer
1386 statement, and its array specification (if any) may be declared
1387 before, during, or after the pointer statement. The pointer may be
1388 declared as an integer prior to the pointer statement. However, some
1389 machines have default integer sizes that are different than the size
1390 of a pointer, and so the following code is not portable:
1395 If a pointer is declared with a kind that is too small, the compiler
1396 will issue a warning; the resulting binary will probably not work
1397 correctly, because the memory addresses stored in the pointers may be
1398 truncated. It is safer to omit the first line of the above example;
1399 if explicit declaration of ipt's type is omitted, then the compiler
1400 will ensure that ipt is an integer variable large enough to hold a
1403 Pointer arithmetic is valid with Cray pointers, but it is not the same
1404 as C pointer arithmetic. Cray pointers are just ordinary integers, so
1405 the user is responsible for determining how many bytes to add to a
1406 pointer in order to increment it. Consider the following example:
1410 pointer (ipt, pointee)
1414 The last statement does not set @code{ipt} to the address of
1415 @code{target(1)}, as it would in C pointer arithmetic. Adding @code{1}
1416 to @code{ipt} just adds one byte to the address stored in @code{ipt}.
1418 Any expression involving the pointee will be translated to use the
1419 value stored in the pointer as the base address.
1421 To get the address of elements, this extension provides an intrinsic
1422 function @code{LOC()}. The @code{LOC()} function is equivalent to the
1423 @code{&} operator in C, except the address is cast to an integer type:
1426 pointer(ipt, arpte(10))
1428 ipt = loc(ar) ! Makes arpte is an alias for ar
1429 arpte(1) = 1.0 ! Sets ar(1) to 1.0
1431 The pointer can also be set by a call to the @code{MALLOC} intrinsic
1434 Cray pointees often are used to alias an existing variable. For
1442 As long as @code{ipt} remains unchanged, @code{iarr} is now an alias for
1443 @code{target}. The optimizer, however, will not detect this aliasing, so
1444 it is unsafe to use @code{iarr} and @code{target} simultaneously. Using
1445 a pointee in any way that violates the Fortran aliasing rules or
1446 assumptions is illegal. It is the user's responsibility to avoid doing
1447 this; the compiler works under the assumption that no such aliasing
1450 Cray pointers will work correctly when there is no aliasing (i.e., when
1451 they are used to access a dynamically allocated block of memory), and
1452 also in any routine where a pointee is used, but any variable with which
1453 it shares storage is not used. Code that violates these rules may not
1454 run as the user intends. This is not a bug in the optimizer; any code
1455 that violates the aliasing rules is illegal. (Note that this is not
1456 unique to GNU Fortran; any Fortran compiler that supports Cray pointers
1457 will ``incorrectly'' optimize code with illegal aliasing.)
1459 There are a number of restrictions on the attributes that can be applied
1460 to Cray pointers and pointees. Pointees may not have the
1461 @code{ALLOCATABLE}, @code{INTENT}, @code{OPTIONAL}, @code{DUMMY},
1462 @code{TARGET}, @code{INTRINSIC}, or @code{POINTER} attributes. Pointers
1463 may not have the @code{DIMENSION}, @code{POINTER}, @code{TARGET},
1464 @code{ALLOCATABLE}, @code{EXTERNAL}, or @code{INTRINSIC} attributes.
1465 Pointees may not occur in more than one pointer statement. A pointee
1466 cannot be a pointer. Pointees cannot occur in equivalence, common, or
1469 A Cray pointer may also point to a function or a subroutine. For
1470 example, the following excerpt is valid:
1474 pointer (subptr,subpte)
1484 A pointer may be modified during the course of a program, and this
1485 will change the location to which the pointee refers. However, when
1486 pointees are passed as arguments, they are treated as ordinary
1487 variables in the invoked function. Subsequent changes to the pointer
1488 will not change the base address of the array that was passed.
1490 @node CONVERT specifier
1491 @subsection @code{CONVERT} specifier
1492 @cindex @code{CONVERT} specifier
1494 GNU Fortran allows the conversion of unformatted data between little-
1495 and big-endian representation to facilitate moving of data
1496 between different systems. The conversion can be indicated with
1497 the @code{CONVERT} specifier on the @code{OPEN} statement.
1498 @xref{GFORTRAN_CONVERT_UNIT}, for an alternative way of specifying
1499 the data format via an environment variable.
1501 Valid values for @code{CONVERT} are:
1503 @item @code{CONVERT='NATIVE'} Use the native format. This is the default.
1504 @item @code{CONVERT='SWAP'} Swap between little- and big-endian.
1505 @item @code{CONVERT='LITTLE_ENDIAN'} Use the little-endian representation
1506 for unformatted files.
1507 @item @code{CONVERT='BIG_ENDIAN'} Use the big-endian representation for
1511 Using the option could look like this:
1513 open(file='big.dat',form='unformatted',access='sequential', &
1514 convert='big_endian')
1517 The value of the conversion can be queried by using
1518 @code{INQUIRE(CONVERT=ch)}. The values returned are
1519 @code{'BIG_ENDIAN'} and @code{'LITTLE_ENDIAN'}.
1521 @code{CONVERT} works between big- and little-endian for
1522 @code{INTEGER} values of all supported kinds and for @code{REAL}
1523 on IEEE systems of kinds 4 and 8. Conversion between different
1524 ``extended double'' types on different architectures such as
1525 m68k and x86_64, which GNU Fortran
1526 supports as @code{REAL(KIND=10)} and @code{REAL(KIND=16)}, will
1529 @emph{Note that the values specified via the GFORTRAN_CONVERT_UNIT
1530 environment variable will override the CONVERT specifier in the
1531 open statement}. This is to give control over data formats to
1532 users who do not have the source code of their program available.
1534 Using anything but the native representation for unformatted data
1535 carries a significant speed overhead. If speed in this area matters
1536 to you, it is best if you use this only for data that needs to be
1543 OpenMP (Open Multi-Processing) is an application programming
1544 interface (API) that supports multi-platform shared memory
1545 multiprocessing programming in C/C++ and Fortran on many
1546 architectures, including Unix and Microsoft Windows platforms.
1547 It consists of a set of compiler directives, library routines,
1548 and environment variables that influence run-time behavior.
1550 GNU Fortran strives to be compatible to the
1551 @uref{http://www.openmp.org/mp-documents/spec30.pdf,
1552 OpenMP Application Program Interface v3.0}.
1554 To enable the processing of the OpenMP directive @code{!$omp} in
1555 free-form source code; the @code{c$omp}, @code{*$omp} and @code{!$omp}
1556 directives in fixed form; the @code{!$} conditional compilation sentinels
1557 in free form; and the @code{c$}, @code{*$} and @code{!$} sentinels
1558 in fixed form, @command{gfortran} needs to be invoked with the
1559 @option{-fopenmp}. This also arranges for automatic linking of the
1560 GNU OpenMP runtime library @ref{Top,,libgomp,libgomp,GNU OpenMP
1563 The OpenMP Fortran runtime library routines are provided both in a
1564 form of a Fortran 90 module named @code{omp_lib} and in a form of
1565 a Fortran @code{include} file named @file{omp_lib.h}.
1567 An example of a parallelized loop taken from Appendix A.1 of
1568 the OpenMP Application Program Interface v2.5:
1570 SUBROUTINE A1(N, A, B)
1573 !$OMP PARALLEL DO !I is private by default
1575 B(I) = (A(I) + A(I-1)) / 2.0
1577 !$OMP END PARALLEL DO
1584 @option{-fopenmp} implies @option{-frecursive}, i.e., all local arrays
1585 will be allocated on the stack. When porting existing code to OpenMP,
1586 this may lead to surprising results, especially to segmentation faults
1587 if the stacksize is limited.
1590 On glibc-based systems, OpenMP enabled applications cannot be statically
1591 linked due to limitations of the underlying pthreads-implementation. It
1592 might be possible to get a working solution if
1593 @command{-Wl,--whole-archive -lpthread -Wl,--no-whole-archive} is added
1594 to the command line. However, this is not supported by @command{gcc} and
1595 thus not recommended.
1598 @node Argument list functions
1599 @subsection Argument list functions @code{%VAL}, @code{%REF} and @code{%LOC}
1600 @cindex argument list functions
1605 GNU Fortran supports argument list functions @code{%VAL}, @code{%REF}
1606 and @code{%LOC} statements, for backward compatibility with g77.
1607 It is recommended that these should be used only for code that is
1608 accessing facilities outside of GNU Fortran, such as operating system
1609 or windowing facilities. It is best to constrain such uses to isolated
1610 portions of a program--portions that deal specifically and exclusively
1611 with low-level, system-dependent facilities. Such portions might well
1612 provide a portable interface for use by the program as a whole, but are
1613 themselves not portable, and should be thoroughly tested each time they
1614 are rebuilt using a new compiler or version of a compiler.
1616 @code{%VAL} passes a scalar argument by value, @code{%REF} passes it by
1617 reference and @code{%LOC} passes its memory location. Since gfortran
1618 already passes scalar arguments by reference, @code{%REF} is in effect
1619 a do-nothing. @code{%LOC} has the same effect as a Fortran pointer.
1621 An example of passing an argument by value to a C subroutine foo.:
1624 C prototype void foo_ (float x);
1633 For details refer to the g77 manual
1634 @uref{http://gcc.gnu.org/onlinedocs/gcc-3.4.6/g77/index.html#Top}.
1636 Also, @code{c_by_val.f} and its partner @code{c_by_val.c} of the
1637 GNU Fortran testsuite are worth a look.
1640 @node Extensions not implemented in GNU Fortran
1641 @section Extensions not implemented in GNU Fortran
1642 @cindex extensions, not implemented
1644 The long history of the Fortran language, its wide use and broad
1645 userbase, the large number of different compiler vendors and the lack of
1646 some features crucial to users in the first standards have lead to the
1647 existence of a number of important extensions to the language. While
1648 some of the most useful or popular extensions are supported by the GNU
1649 Fortran compiler, not all existing extensions are supported. This section
1650 aims at listing these extensions and offering advice on how best make
1651 code that uses them running with the GNU Fortran compiler.
1653 @c More can be found here:
1654 @c -- http://gcc.gnu.org/onlinedocs/gcc-3.4.6/g77/Missing-Features.html
1655 @c -- the list of Fortran and libgfortran bugs closed as WONTFIX:
1656 @c http://tinyurl.com/2u4h5y
1659 * STRUCTURE and RECORD::
1660 @c * UNION and MAP::
1661 * ENCODE and DECODE statements::
1662 * Variable FORMAT expressions::
1663 @c * Q edit descriptor::
1664 @c * AUTOMATIC statement::
1665 @c * TYPE and ACCEPT I/O Statements::
1666 @c * .XOR. operator::
1667 @c * CARRIAGECONTROL, DEFAULTFILE, DISPOSE and RECORDTYPE I/O specifiers::
1668 @c * Omitted arguments in procedure call:
1672 @node STRUCTURE and RECORD
1673 @subsection @code{STRUCTURE} and @code{RECORD}
1674 @cindex @code{STRUCTURE}
1675 @cindex @code{RECORD}
1677 Structures are user-defined aggregate data types; this functionality was
1678 standardized in Fortran 90 with an different syntax, under the name of
1679 ``derived types''. Here is an example of code using the non portable
1683 ! Declaring a structure named ``item'' and containing three fields:
1684 ! an integer ID, an description string and a floating-point price.
1687 CHARACTER(LEN=200) description
1691 ! Define two variables, an single record of type ``item''
1692 ! named ``pear'', and an array of items named ``store_catalog''
1693 RECORD /item/ pear, store_catalog(100)
1695 ! We can directly access the fields of both variables
1697 pear.description = "juicy D'Anjou pear"
1699 store_catalog(7).id = 7831
1700 store_catalog(7).description = "milk bottle"
1701 store_catalog(7).price = 1.2
1703 ! We can also manipulate the whole structure
1704 store_catalog(12) = pear
1705 print *, store_catalog(12)
1709 This code can easily be rewritten in the Fortran 90 syntax as following:
1712 ! ``STRUCTURE /name/ ... END STRUCTURE'' becomes
1713 ! ``TYPE name ... END TYPE''
1716 CHARACTER(LEN=200) description
1720 ! ``RECORD /name/ variable'' becomes ``TYPE(name) variable''
1721 TYPE(item) pear, store_catalog(100)
1723 ! Instead of using a dot (.) to access fields of a record, the
1724 ! standard syntax uses a percent sign (%)
1726 pear%description = "juicy D'Anjou pear"
1728 store_catalog(7)%id = 7831
1729 store_catalog(7)%description = "milk bottle"
1730 store_catalog(7)%price = 1.2
1732 ! Assignments of a whole variable don't change
1733 store_catalog(12) = pear
1734 print *, store_catalog(12)
1738 @c @node UNION and MAP
1739 @c @subsection @code{UNION} and @code{MAP}
1740 @c @cindex @code{UNION}
1741 @c @cindex @code{MAP}
1743 @c For help writing this one, see
1744 @c http://www.eng.umd.edu/~nsw/ench250/fortran1.htm#UNION and
1745 @c http://www.tacc.utexas.edu/services/userguides/pgi/pgiws_ug/pgi32u06.htm
1748 @node ENCODE and DECODE statements
1749 @subsection @code{ENCODE} and @code{DECODE} statements
1750 @cindex @code{ENCODE}
1751 @cindex @code{DECODE}
1753 GNU Fortran doesn't support the @code{ENCODE} and @code{DECODE}
1754 statements. These statements are best replaced by @code{READ} and
1755 @code{WRITE} statements involving internal files (@code{CHARACTER}
1756 variables and arrays), which have been part of the Fortran standard since
1757 Fortran 77. For example, replace a code fragment like
1762 c ... Code that sets LINE
1763 DECODE (80, 9000, LINE) A, B, C
1764 9000 FORMAT (1X, 3(F10.5))
1771 CHARACTER(LEN=80) LINE
1773 c ... Code that sets LINE
1774 READ (UNIT=LINE, FMT=9000) A, B, C
1775 9000 FORMAT (1X, 3(F10.5))
1778 Similarly, replace a code fragment like
1783 c ... Code that sets A, B and C
1784 ENCODE (80, 9000, LINE) A, B, C
1785 9000 FORMAT (1X, 'OUTPUT IS ', 3(F10.5))
1794 c ... Code that sets A, B and C
1795 WRITE (UNIT=LINE, FMT=9000) A, B, C
1796 9000 FORMAT (1X, 'OUTPUT IS ', 3(F10.5))
1800 @node Variable FORMAT expressions
1801 @subsection Variable @code{FORMAT} expressions
1802 @cindex @code{FORMAT}
1804 A variable @code{FORMAT} expression is format statement which includes
1805 angle brackets enclosing a Fortran expression: @code{FORMAT(I<N>)}. GNU
1806 Fortran does not support this legacy extension. The effect of variable
1807 format expressions can be reproduced by using the more powerful (and
1808 standard) combination of internal output and string formats. For example,
1809 replace a code fragment like this:
1820 c Variable declaration
1823 c Other code here...
1825 WRITE(FMT,'("(I", I0, ")")') N+1
1833 c Variable declaration
1834 CHARACTER(LEN=20) FMT
1836 c Other code here...
1839 WRITE(6,"(I" // ADJUSTL(FMT) // ")") INT1
1843 @c ---------------------------------------------------------------------
1844 @c Mixed-Language Programming
1845 @c ---------------------------------------------------------------------
1847 @node Mixed-Language Programming
1848 @chapter Mixed-Language Programming
1849 @cindex Interoperability
1850 @cindex Mixed-language programming
1853 * Interoperability with C::
1854 * Non-Fortran Main Program::
1857 This chapter is about mixed-language interoperability, but also applies
1858 if one links Fortran code compiled by different compilers. In most cases,
1859 use of the C Binding features of the Fortran 2003 standard is sufficient,
1860 and their use is highly recommended.
1863 @node Interoperability with C
1864 @section Interoperability with C
1868 * Further Interoperability of Fortran with C::
1869 * Derived Types and struct::
1870 * Interoperable Global Variables::
1871 * Interoperable Subroutines and Functions::
1874 Since Fortran 2003 (ISO/IEC 1539-1:2004(E)) there is a
1875 standardized way to generate procedure and derived-type
1876 declarations and global variables which are interoperable with C
1877 (ISO/IEC 9899:1999). The @code{bind(C)} attribute has been added
1878 to inform the compiler that a symbol shall be interoperable with C;
1879 also, some constraints are added. Note, however, that not
1880 all C features have a Fortran equivalent or vice versa. For instance,
1881 neither C's unsigned integers nor C's functions with variable number
1882 of arguments have an equivalent in Fortran.
1885 @node Intrinsic Types
1886 @subsection Intrinsic Types
1888 In order to ensure that exactly the same variable type and kind is used
1889 in C and Fortran, the named constants shall be used which are defined in the
1890 @code{ISO_C_BINDING} intrinsic module. That module contains named constants
1891 for kind parameters and character named constants for the escape sequences
1892 in C. For a list of the constants, see @ref{ISO_C_BINDING}.
1894 @node Derived Types and struct
1895 @subsection Derived Types and struct
1897 For compatibility of derived types with @code{struct}, one needs to use
1898 the @code{BIND(C)} attribute in the type declaration. For instance, the
1899 following type declaration
1903 TYPE, BIND(C) :: myType
1904 INTEGER(C_INT) :: i1, i2
1905 INTEGER(C_SIGNED_CHAR) :: i3
1906 REAL(C_DOUBLE) :: d1
1907 COMPLEX(C_FLOAT_COMPLEX) :: c1
1908 CHARACTER(KIND=C_CHAR) :: str(5)
1912 matches the following @code{struct} declaration in C
1917 /* Note: "char" might be signed or unsigned. */
1925 Derived types with the C binding attribute shall not have the @code{sequence}
1926 attribute, type parameters, the @code{extends} attribute, nor type-bound
1927 procedures. Every component must be of interoperable type and kind and may not
1928 have the @code{pointer} or @code{allocatable} attribute. The names of the
1929 variables are irrelevant for interoperability.
1931 As there exist no direct Fortran equivalents, neither unions nor structs
1932 with bit field or variable-length array members are interoperable.
1934 @node Interoperable Global Variables
1935 @subsection Interoperable Global Variables
1937 Variables can be made accessible from C using the C binding attribute,
1938 optionally together with specifying a binding name. Those variables
1939 have to be declared in the declaration part of a @code{MODULE},
1940 be of interoperable type, and have neither the @code{pointer} nor
1941 the @code{allocatable} attribute.
1947 integer(C_INT), bind(C, name="_MyProject_flags") :: global_flag
1948 type(myType), bind(C) :: tp
1952 Here, @code{_MyProject_flags} is the case-sensitive name of the variable
1953 as seen from C programs while @code{global_flag} is the case-insensitive
1954 name as seen from Fortran. If no binding name is specified, as for
1955 @var{tp}, the C binding name is the (lowercase) Fortran binding name.
1956 If a binding name is specified, only a single variable may be after the
1957 double colon. Note of warning: You cannot use a global variable to
1958 access @var{errno} of the C library as the C standard allows it to be
1959 a macro. Use the @code{IERRNO} intrinsic (GNU extension) instead.
1961 @node Interoperable Subroutines and Functions
1962 @subsection Interoperable Subroutines and Functions
1964 Subroutines and functions have to have the @code{BIND(C)} attribute to
1965 be compatible with C. The dummy argument declaration is relatively
1966 straightforward. However, one needs to be careful because C uses
1967 call-by-value by default while GNU Fortran uses call-by-reference.
1968 Furthermore, strings and pointers are handled differently. Note that
1969 only explicit size and assumed-size arrays are supported but not
1970 assumed-shape or allocatable arrays.
1972 To pass a variable by value, use the @code{VALUE} attribute.
1973 Thus the following C prototype
1976 @code{int func(int i, int *j)}
1979 matches the Fortran declaration
1982 integer(c_int) func(i,j)
1987 Note that pointer arguments also frequently need the @code{VALUE} attribute.
1989 Strings are handled quite differently in C and Fortran. In C a string
1990 is a @code{NUL}-terminated array of characters while in Fortran each string
1991 has a length associated with it and is thus not terminated (by e.g.
1992 @code{NUL}). For example, if one wants to use the following C function,
1996 void print_C(char *string) /* equivalent: char string[] */
1998 printf("%s\n", string);
2002 to print ``Hello World'' from Fortran, one can call it using
2005 use iso_c_binding, only: C_CHAR, C_NULL_CHAR
2007 subroutine print_c(string) bind(C, name="print_C")
2008 use iso_c_binding, only: c_char
2009 character(kind=c_char) :: string(*)
2010 end subroutine print_c
2012 call print_c(C_CHAR_"Hello World"//C_NULL_CHAR)
2015 As the example shows, one needs to ensure that the
2016 string is @code{NUL} terminated. Additionally, the dummy argument
2017 @var{string} of @code{print_C} is a length-one assumed-size
2018 array; using @code{character(len=*)} is not allowed. The example
2019 above uses @code{c_char_"Hello World"} to ensure the string
2020 literal has the right type; typically the default character
2021 kind and @code{c_char} are the same and thus @code{"Hello World"}
2022 is equivalent. However, the standard does not guarantee this.
2024 The use of pointers is now illustrated using the C library
2025 function @code{strncpy}, whose prototype is
2028 char *strncpy(char *restrict s1, const char *restrict s2, size_t n);
2031 The function @code{strncpy} copies at most @var{n} characters from
2032 string @var{s2} to @var{s1} and returns @var{s1}. In the following
2033 example, we ignore the return value:
2038 character(len=30) :: str,str2
2040 ! Ignore the return value of strncpy -> subroutine
2041 ! "restrict" is always assumed if we do not pass a pointer
2042 subroutine strncpy(dest, src, n) bind(C)
2044 character(kind=c_char), intent(out) :: dest(*)
2045 character(kind=c_char), intent(in) :: src(*)
2046 integer(c_size_t), value, intent(in) :: n
2047 end subroutine strncpy
2049 str = repeat('X',30) ! Initialize whole string with 'X'
2050 call strncpy(str, c_char_"Hello World"//C_NULL_CHAR, &
2051 len(c_char_"Hello World",kind=c_size_t))
2052 print '(a)', str ! prints: "Hello WorldXXXXXXXXXXXXXXXXXXX"
2056 C pointers are represented in Fortran via the special derived type
2057 @code{type(c_ptr)}, with private components. Thus one needs to
2058 use intrinsic conversion procedures to convert from or to C pointers.
2063 type(c_ptr) :: cptr1, cptr2
2064 integer, target :: array(7), scalar
2065 integer, pointer :: pa(:), ps
2066 cptr1 = c_loc(array(1)) ! The programmer needs to ensure that the
2067 ! array is contiguous if required by the C
2069 cptr2 = c_loc(scalar)
2070 call c_f_pointer(cptr2, ps)
2071 call c_f_pointer(cptr2, pa, shape=[7])
2074 When converting C to Fortran arrays, the one-dimensional @code{SHAPE} argument
2075 has to be passed. Note: A pointer argument @code{void *} matches
2076 @code{TYPE(C_PTR), VALUE} while @code{TYPE(C_PTR)} matches @code{void **}.
2078 Procedure pointers are handled analogously to pointers; the C type is
2079 @code{TYPE(C_FUNPTR)} and the intrinsic conversion procedures are
2080 @code{C_F_PROC_POINTER} and @code{C_FUNLOC}.
2082 The intrinsic procedures are described in @ref{Intrinsic Procedures}.
2084 @node Further Interoperability of Fortran with C
2085 @subsection Further Interoperability of Fortran with C
2087 Assumed-shape and allocatable arrays are passed using an array descriptor
2088 (dope vector). The internal structure of the array descriptor used
2089 by GNU Fortran is not yet documented and will change. There will also be
2090 a Technical Report (TR 29113) which standardizes an interoperable
2091 array descriptor. Until then, you can use the Chasm Language
2092 Interoperability Tools, @url{http://chasm-interop.sourceforge.net/},
2093 which provide an interface to GNU Fortran's array descriptor.
2095 The technical report 29113 will presumably also include support for
2096 C-interoperable @code{OPTIONAL} and for assumed-rank and assumed-type
2097 dummy arguments. However, the TR has neither been approved nor implemented
2098 in GNU Fortran; therefore, these features are not yet available.
2100 @node Non-Fortran Main Program
2101 @section Non-Fortran Main Program
2104 * _gfortran_set_args:: Save command-line arguments
2105 * _gfortran_set_options:: Set library option flags
2106 * _gfortran_set_convert:: Set endian conversion
2107 * _gfortran_set_record_marker:: Set length of record markers
2108 * _gfortran_set_max_subrecord_length:: Set subrecord length
2111 Even if you are doing mixed-language programming, it is very
2112 likely that you do not need to know or use the information in this
2113 section. Since it is about the internal structure of GNU Fortran,
2114 it may also change in GCC minor releases.
2116 When you compile a @code{PROGRAM} with GNU Fortran, a function
2117 with the name @code{main} (in the symbol table of the object file)
2118 is generated, which initializes the libgfortran library and then
2119 calls the actual program which uses the name @code{MAIN__}, for
2120 historic reasons. If you link GNU Fortran compiled procedures
2121 to, e.g., a C or C++ program or to a Fortran program compiled by
2122 a different compiler, the libgfortran library is not initialized
2123 and thus a few intrinsic procedures do not work properly, e.g.
2124 those for obtaining the command-line arguments.
2126 Therefore, if your @code{PROGRAM} is not compiled with
2127 GNU Fortran and the GNU Fortran compiled procedures require
2128 intrinsics relying on the library initialization, you need to
2129 initialize the library yourself. Using the default options,
2130 gfortran calls @code{_gfortran_set_args} and
2131 @code{_gfortran_set_options}. The initialization of the former
2132 is needed if the called procedures access the command line
2133 (and for backtracing); the latter sets some flags based on the
2134 standard chosen or to enable backtracing. In typical programs,
2135 it is not necessary to call any initialization function.
2137 If your @code{PROGRAM} is compiled with GNU Fortran, you shall
2138 not call any of the following functions. The libgfortran
2139 initialization functions are shown in C syntax but using C
2140 bindings they are also accessible from Fortran.
2143 @node _gfortran_set_args
2144 @subsection @code{_gfortran_set_args} --- Save command-line arguments
2145 @fnindex _gfortran_set_args
2146 @cindex libgfortran initialization, set_args
2149 @item @emph{Description}:
2150 @code{_gfortran_set_args} saves the command-line arguments; this
2151 initialization is required if any of the command-line intrinsics
2152 is called. Additionally, it shall be called if backtracing is
2153 enabled (see @code{_gfortran_set_options}).
2155 @item @emph{Syntax}:
2156 @code{void _gfortran_set_args (int argc, char *argv[])}
2158 @item @emph{Arguments}:
2159 @multitable @columnfractions .15 .70
2160 @item @var{argc} @tab number of command line argument strings
2161 @item @var{argv} @tab the command-line argument strings; argv[0]
2162 is the pathname of the executable itself.
2165 @item @emph{Example}:
2167 int main (int argc, char *argv[])
2169 /* Initialize libgfortran. */
2170 _gfortran_set_args (argc, argv);
2177 @node _gfortran_set_options
2178 @subsection @code{_gfortran_set_options} --- Set library option flags
2179 @fnindex _gfortran_set_options
2180 @cindex libgfortran initialization, set_options
2183 @item @emph{Description}:
2184 @code{_gfortran_set_options} sets several flags related to the Fortran
2185 standard to be used, whether backtracing or core dumps should be enabled
2186 and whether range checks should be performed. The syntax allows for
2187 upward compatibility since the number of passed flags is specified; for
2188 non-passed flags, the default value is used. See also
2189 @pxref{Code Gen Options}. Please note that not all flags are actually
2192 @item @emph{Syntax}:
2193 @code{void _gfortran_set_options (int num, int options[])}
2195 @item @emph{Arguments}:
2196 @multitable @columnfractions .15 .70
2197 @item @var{num} @tab number of options passed
2198 @item @var{argv} @tab The list of flag values
2201 @item @emph{option flag list}:
2202 @multitable @columnfractions .15 .70
2203 @item @var{option}[0] @tab Allowed standard; can give run-time errors
2204 if e.g. an input-output edit descriptor is invalid in a given standard.
2205 Possible values are (bitwise or-ed) @code{GFC_STD_F77} (1),
2206 @code{GFC_STD_F95_OBS} (2), @code{GFC_STD_F95_DEL} (4), @code{GFC_STD_F95}
2207 (8), @code{GFC_STD_F2003} (16), @code{GFC_STD_GNU} (32),
2208 @code{GFC_STD_LEGACY} (64), and @code{GFC_STD_F2008} (128).
2209 Default: @code{GFC_STD_F95_OBS | GFC_STD_F95_DEL | GFC_STD_F2003
2210 | GFC_STD_F2008 | GFC_STD_F95 | GFC_STD_F77 | GFC_STD_GNU | GFC_STD_LEGACY}.
2211 @item @var{option}[1] @tab Standard-warning flag; prints a warning to
2212 standard error. Default: @code{GFC_STD_F95_DEL | GFC_STD_LEGACY}.
2213 @item @var{option}[2] @tab If non zero, enable pedantic checking.
2215 @item @var{option}[3] @tab If non zero, enable core dumps on run-time
2216 errors. Default: off.
2217 @item @var{option}[4] @tab If non zero, enable backtracing on run-time
2218 errors. Default: off.
2219 Note: Installs a signal handler and requires command-line
2220 initialization using @code{_gfortran_set_args}.
2221 @item @var{option}[5] @tab If non zero, supports signed zeros.
2223 @item @var{option}[6] @tab Enables run-time checking. Possible values
2224 are (bitwise or-ed): GFC_RTCHECK_BOUNDS (1), GFC_RTCHECK_ARRAY_TEMPS (2),
2225 GFC_RTCHECK_RECURSION (4), GFC_RTCHECK_DO (16).
2227 @item @var{option}[7] @tab If non zero, range checking is enabled.
2228 Default: enabled. See -frange-check (@pxref{Code Gen Options}).
2231 @item @emph{Example}:
2233 /* Use gfortran 4.5 default options. */
2234 static int options[] = @{68, 255, 0, 0, 0, 1, 0, 1@};
2235 _gfortran_set_options (8, &options);
2240 @node _gfortran_set_convert
2241 @subsection @code{_gfortran_set_convert} --- Set endian conversion
2242 @fnindex _gfortran_set_convert
2243 @cindex libgfortran initialization, set_convert
2246 @item @emph{Description}:
2247 @code{_gfortran_set_convert} set the representation of data for
2250 @item @emph{Syntax}:
2251 @code{void _gfortran_set_convert (int conv)}
2253 @item @emph{Arguments}:
2254 @multitable @columnfractions .15 .70
2255 @item @var{conv} @tab Endian conversion, possible values:
2256 GFC_CONVERT_NATIVE (0, default), GFC_CONVERT_SWAP (1),
2257 GFC_CONVERT_BIG (2), GFC_CONVERT_LITTLE (3).
2260 @item @emph{Example}:
2262 int main (int argc, char *argv[])
2264 /* Initialize libgfortran. */
2265 _gfortran_set_args (argc, argv);
2266 _gfortran_set_convert (1);
2273 @node _gfortran_set_record_marker
2274 @subsection @code{_gfortran_set_record_marker} --- Set length of record markers
2275 @fnindex _gfortran_set_record_marker
2276 @cindex libgfortran initialization, set_record_marker
2279 @item @emph{Description}:
2280 @code{_gfortran_set_record_marker} set the length of record markers
2281 for unformatted files.
2283 @item @emph{Syntax}:
2284 @code{void _gfortran_set_record_marker (int val)}
2286 @item @emph{Arguments}:
2287 @multitable @columnfractions .15 .70
2288 @item @var{val} @tab Length of the record marker; valid values
2289 are 4 and 8. Default is 4.
2292 @item @emph{Example}:
2294 int main (int argc, char *argv[])
2296 /* Initialize libgfortran. */
2297 _gfortran_set_args (argc, argv);
2298 _gfortran_set_record_marker (8);
2305 @node _gfortran_set_max_subrecord_length
2306 @subsection @code{_gfortran_set_max_subrecord_length} --- Set subrecord length
2307 @fnindex _gfortran_set_max_subrecord_length
2308 @cindex libgfortran initialization, set_max_subrecord_length
2311 @item @emph{Description}:
2312 @code{_gfortran_set_max_subrecord_length} set the maximum length
2313 for a subrecord. This option only makes sense for testing and
2314 debugging of unformatted I/O.
2316 @item @emph{Syntax}:
2317 @code{void _gfortran_set_max_subrecord_length (int val)}
2319 @item @emph{Arguments}:
2320 @multitable @columnfractions .15 .70
2321 @item @var{val} @tab the maximum length for a subrecord;
2322 the maximum permitted value is 2147483639, which is also
2326 @item @emph{Example}:
2328 int main (int argc, char *argv[])
2330 /* Initialize libgfortran. */
2331 _gfortran_set_args (argc, argv);
2332 _gfortran_set_max_subrecord_length (8);
2340 @c Intrinsic Procedures
2341 @c ---------------------------------------------------------------------
2343 @include intrinsic.texi
2350 @c ---------------------------------------------------------------------
2352 @c ---------------------------------------------------------------------
2355 @unnumbered Contributing
2356 @cindex Contributing
2358 Free software is only possible if people contribute to efforts
2360 We're always in need of more people helping out with ideas
2361 and comments, writing documentation and contributing code.
2363 If you want to contribute to GNU Fortran,
2364 have a look at the long lists of projects you can take on.
2365 Some of these projects are small,
2366 some of them are large;
2367 some are completely orthogonal to the rest of what is
2368 happening on GNU Fortran,
2369 but others are ``mainstream'' projects in need of enthusiastic hackers.
2370 All of these projects are important!
2371 We'll eventually get around to the things here,
2372 but they are also things doable by someone who is willing and able.
2377 * Proposed Extensions::
2382 @section Contributors to GNU Fortran
2383 @cindex Contributors
2387 Most of the parser was hand-crafted by @emph{Andy Vaught}, who is
2388 also the initiator of the whole project. Thanks Andy!
2389 Most of the interface with GCC was written by @emph{Paul Brook}.
2391 The following individuals have contributed code and/or
2392 ideas and significant help to the GNU Fortran project
2393 (in alphabetical order):
2396 @item Janne Blomqvist
2397 @item Steven Bosscher
2400 @item Fran@,{c}ois-Xavier Coudert
2404 @item Bernhard Fischer
2406 @item Richard Guenther
2407 @item Richard Henderson
2408 @item Katherine Holcomb
2410 @item Niels Kristian Bech Jensen
2411 @item Steven Johnson
2412 @item Steven G. Kargl
2420 @item Christopher D. Rickett
2421 @item Richard Sandiford
2422 @item Tobias Schl@"uter
2431 The following people have contributed bug reports,
2432 smaller or larger patches,
2433 and much needed feedback and encouragement for the
2434 GNU Fortran project:
2438 @item Dominique d'Humi@`eres
2440 @item Erik Schnetter
2441 @item Joost VandeVondele
2444 Many other individuals have helped debug,
2445 test and improve the GNU Fortran compiler over the past few years,
2446 and we welcome you to do the same!
2447 If you already have done so,
2448 and you would like to see your name listed in the
2449 list above, please contact us.
2457 @item Help build the test suite
2458 Solicit more code for donation to the test suite: the more extensive the
2459 testsuite, the smaller the risk of breaking things in the future! We can
2460 keep code private on request.
2462 @item Bug hunting/squishing
2463 Find bugs and write more test cases! Test cases are especially very
2464 welcome, because it allows us to concentrate on fixing bugs instead of
2465 isolating them. Going through the bugzilla database at
2466 @url{http://gcc.gnu.org/bugzilla/} to reduce testcases posted there and
2467 add more information (for example, for which version does the testcase
2468 work, for which versions does it fail?) is also very helpful.
2473 @node Proposed Extensions
2474 @section Proposed Extensions
2476 Here's a list of proposed extensions for the GNU Fortran compiler, in no particular
2477 order. Most of these are necessary to be fully compatible with
2478 existing Fortran compilers, but they are not part of the official
2479 J3 Fortran 95 standard.
2481 @subsection Compiler extensions:
2484 User-specified alignment rules for structures.
2487 Flag to generate @code{Makefile} info.
2490 Automatically extend single precision constants to double.
2493 Compile code that conserves memory by dynamically allocating common and
2494 module storage either on stack or heap.
2497 Compile flag to generate code for array conformance checking (suggest -CC).
2500 User control of symbol names (underscores, etc).
2503 Compile setting for maximum size of stack frame size before spilling
2504 parts to static or heap.
2507 Flag to force local variables into static space.
2510 Flag to force local variables onto stack.
2514 @subsection Environment Options
2517 Pluggable library modules for random numbers, linear algebra.
2518 LA should use BLAS calling conventions.
2521 Environment variables controlling actions on arithmetic exceptions like
2522 overflow, underflow, precision loss---Generate NaN, abort, default.
2526 Set precision for fp units that support it (i387).
2529 Variable for setting fp rounding mode.
2532 Variable to fill uninitialized variables with a user-defined bit
2536 Environment variable controlling filename that is opened for that unit
2540 Environment variable to clear/trash memory being freed.
2543 Environment variable to control tracing of allocations and frees.
2546 Environment variable to display allocated memory at normal program end.
2549 Environment variable for filename for * IO-unit.
2552 Environment variable for temporary file directory.
2555 Environment variable forcing standard output to be line buffered (unix).
2560 @c ---------------------------------------------------------------------
2561 @c GNU General Public License
2562 @c ---------------------------------------------------------------------
2564 @include gpl_v3.texi
2568 @c ---------------------------------------------------------------------
2569 @c GNU Free Documentation License
2570 @c ---------------------------------------------------------------------
2576 @c ---------------------------------------------------------------------
2577 @c Funding Free Software
2578 @c ---------------------------------------------------------------------
2580 @include funding.texi
2582 @c ---------------------------------------------------------------------
2584 @c ---------------------------------------------------------------------
2587 @unnumbered Option Index
2588 @command{gfortran}'s command line options are indexed here without any
2589 initial @samp{-} or @samp{--}. Where an option has both positive and
2590 negative forms (such as -foption and -fno-option), relevant entries in
2591 the manual are indexed under the most appropriate form; it may sometimes
2592 be useful to look up both forms.
2596 @unnumbered Keyword Index