1 \input texinfo @c -*-texinfo-*-
3 @setfilename gfortran.info
4 @set copyrights-gfortran 1999-2019
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.3 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 standards status:: Fortran 2003, 2008 and 2018 features supported by GNU Fortran.
184 * Compiler Characteristics:: User-visible implementation details.
185 * Extensions:: Language extensions implemented by GNU Fortran.
186 * Mixed-Language Programming:: Interoperability with C
187 * Coarray Programming::
188 * Intrinsic Procedures:: Intrinsic procedures supported by GNU Fortran.
189 * Intrinsic Modules:: Intrinsic modules supported by GNU Fortran.
191 * Contributing:: How you can help.
192 * Copying:: GNU General Public License says
193 how you can copy and share GNU Fortran.
194 * GNU Free Documentation License::
195 How you can copy and share this manual.
196 * Funding:: How to help assure continued work for free software.
197 * Option Index:: Index of command line options
198 * Keyword Index:: Index of concepts
202 @c ---------------------------------------------------------------------
204 @c ---------------------------------------------------------------------
207 @chapter Introduction
209 @c The following duplicates the text on the TexInfo table of contents.
211 This manual documents the use of @command{gfortran}, the GNU Fortran
212 compiler. You can find in this manual how to invoke @command{gfortran},
213 as well as its features and incompatibilities.
216 @emph{Warning:} This document, and the compiler it describes, are still
217 under development. While efforts are made to keep it up-to-date, it
218 might not accurately reflect the status of the most recent GNU Fortran
223 The GNU Fortran compiler front end was
224 designed initially as a free replacement for,
225 or alternative to, the Unix @command{f95} command;
226 @command{gfortran} is the command you will use to invoke the compiler.
229 * About GNU Fortran:: What you should know about the GNU Fortran compiler.
230 * GNU Fortran and GCC:: You can compile Fortran, C, or other programs.
231 * Preprocessing and conditional compilation:: The Fortran preprocessor
232 * GNU Fortran and G77:: Why we chose to start from scratch.
233 * Project Status:: Status of GNU Fortran, roadmap, proposed extensions.
234 * Standards:: Standards supported by GNU Fortran.
238 @c ---------------------------------------------------------------------
240 @c ---------------------------------------------------------------------
242 @node About GNU Fortran
243 @section About GNU Fortran
245 The GNU Fortran compiler supports the Fortran 77, 90 and 95 standards
246 completely, parts of the Fortran 2003, 2008 and 2018 standards, and
247 several vendor extensions. The development goal is to provide the
252 Read a user's program, stored in a file and containing instructions
253 written in Fortran 77, Fortran 90, Fortran 95, Fortran 2003, Fortran
254 2008 or Fortran 2018. 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 are not 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 @file{.F}, @file{.FOR}, @file{.FTN}, @file{.fpp},
411 @file{.FPP}, @file{.F90}, @file{.F95}, @file{.F03} or @file{.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. The macros @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 GNU Fortran supports a number of @code{INTEGER} and @code{REAL} kind types
426 in additional to the kind types required by the Fortran standard.
427 The availability of any given kind type is architecture dependent. The
428 following pre-defined preprocessor macros can be used to conditionally
429 include code for these additional kind types: @code{__GFC_INT_1__},
430 @code{__GFC_INT_2__}, @code{__GFC_INT_8__}, @code{__GFC_INT_16__},
431 @code{__GFC_REAL_10__}, and @code{__GFC_REAL_16__}.
433 While CPP is the de-facto standard for preprocessing Fortran code,
434 Part 3 of the Fortran 95 standard (ISO/IEC 1539-3:1998) defines
435 Conditional Compilation, which is not widely used and not directly
436 supported by the GNU Fortran compiler. You can use the program coco
437 to preprocess such files (@uref{http://www.daniellnagle.com/coco.html}).
440 @c ---------------------------------------------------------------------
441 @c GNU Fortran and G77
442 @c ---------------------------------------------------------------------
444 @node GNU Fortran and G77
445 @section GNU Fortran and G77
447 @cindex @command{g77}
449 The GNU Fortran compiler is the successor to @command{g77}, the Fortran
450 77 front end included in GCC prior to version 4. It is an entirely new
451 program that has been designed to provide Fortran 95 support and
452 extensibility for future Fortran language standards, as well as providing
453 backwards compatibility for Fortran 77 and nearly all of the GNU language
454 extensions supported by @command{g77}.
457 @c ---------------------------------------------------------------------
459 @c ---------------------------------------------------------------------
462 @section Project Status
465 As soon as @command{gfortran} can parse all of the statements correctly,
466 it will be in the ``larva'' state.
467 When we generate code, the ``puppa'' state.
468 When @command{gfortran} is done,
469 we'll see if it will be a beautiful butterfly,
470 or just a big bug....
472 --Andy Vaught, April 2000
475 The start of the GNU Fortran 95 project was announced on
476 the GCC homepage in March 18, 2000
477 (even though Andy had already been working on it for a while,
480 The GNU Fortran compiler is able to compile nearly all
481 standard-compliant Fortran 95, Fortran 90, and Fortran 77 programs,
482 including a number of standard and non-standard extensions, and can be
483 used on real-world programs. In particular, the supported extensions
484 include OpenMP, Cray-style pointers, some old vendor extensions, and several
485 Fortran 2003 and Fortran 2008 features, including TR 15581. However, it is
486 still under development and has a few remaining rough edges.
487 There also is initial support for OpenACC.
488 Note that this is an experimental feature, incomplete, and subject to
489 change in future versions of GCC. See
490 @uref{https://gcc.gnu.org/wiki/OpenACC} for more information.
492 At present, the GNU Fortran compiler passes the
493 @uref{http://www.fortran-2000.com/ArnaudRecipes/fcvs21_f95.html,
494 NIST Fortran 77 Test Suite}, and produces acceptable results on the
495 @uref{http://www.netlib.org/lapack/faq.html#1.21, LAPACK Test Suite}.
496 It also provides respectable performance on
497 the @uref{http://www.polyhedron.com/fortran-compiler-comparisons/polyhedron-benchmark-suite,
499 compiler benchmarks} and the
500 @uref{http://www.netlib.org/benchmark/livermore,
501 Livermore Fortran Kernels test}. It has been used to compile a number of
502 large real-world programs, including
503 @uref{http://hirlam.org/, the HARMONIE and HIRLAM weather forecasting code} and
504 @uref{http://physical-chemistry.scb.uwa.edu.au/tonto/wiki/index.php/Main_Page,
505 the Tonto quantum chemistry package}; see
506 @url{https://gcc.gnu.org/@/wiki/@/GfortranApps} for an extended list.
508 Among other things, the GNU Fortran compiler is intended as a replacement
509 for G77. At this point, nearly all programs that could be compiled with
510 G77 can be compiled with GNU Fortran, although there are a few minor known
513 The primary work remaining to be done on GNU Fortran falls into three
514 categories: bug fixing (primarily regarding the treatment of invalid
515 code and providing useful error messages), improving the compiler
516 optimizations and the performance of compiled code, and extending the
517 compiler to support future standards---in particular, Fortran 2003,
518 Fortran 2008 and Fortran 2018.
521 @c ---------------------------------------------------------------------
523 @c ---------------------------------------------------------------------
530 * Varying Length Character Strings::
533 The GNU Fortran compiler implements
534 ISO/IEC 1539:1997 (Fortran 95). As such, it can also compile essentially all
535 standard-compliant Fortran 90 and Fortran 77 programs. It also supports
536 the ISO/IEC TR-15581 enhancements to allocatable arrays.
538 GNU Fortran also have a partial support for ISO/IEC 1539-1:2004
539 (Fortran 2003), ISO/IEC 1539-1:2010 (Fortran 2008), the Technical
540 Specification @code{Further Interoperability of Fortran with C}
541 (ISO/IEC TS 29113:2012). Full support of those standards and future
542 Fortran standards is planned. The current status of the support is
543 can be found in the @ref{Fortran 2003 status}, @ref{Fortran 2008
544 status} and @ref{Fortran 2018 status} sections of the documentation.
546 Additionally, the GNU Fortran compilers supports the OpenMP specification
547 (version 4.0 and most of the features of the 4.5 version,
548 @url{http://openmp.org/@/wp/@/openmp-specifications/}).
549 There also is initial support for the OpenACC specification (targeting
550 version 2.0, @uref{http://www.openacc.org/}).
551 Note that this is an experimental feature, incomplete, and subject to
552 change in future versions of GCC. See
553 @uref{https://gcc.gnu.org/wiki/OpenACC} for more information.
555 @node Varying Length Character Strings
556 @subsection Varying Length Character Strings
557 @cindex Varying length character strings
558 @cindex Varying length strings
559 @cindex strings, varying length
561 The Fortran 95 standard specifies in Part 2 (ISO/IEC 1539-2:2000)
562 varying length character strings. While GNU Fortran currently does not
563 support such strings directly, there exist two Fortran implementations
564 for them, which work with GNU Fortran. They can be found at
565 @uref{http://www.fortran.com/@/iso_varying_string.f95} and at
566 @uref{ftp://ftp.nag.co.uk/@/sc22wg5/@/ISO_VARYING_STRING/}.
568 Deferred-length character strings of Fortran 2003 supports part of
569 the features of @code{ISO_VARYING_STRING} and should be considered as
570 replacement. (Namely, allocatable or pointers of the type
571 @code{character(len=:)}.)
574 @c =====================================================================
575 @c PART I: INVOCATION REFERENCE
576 @c =====================================================================
579 \part{I}{Invoking GNU Fortran}
582 @c ---------------------------------------------------------------------
584 @c ---------------------------------------------------------------------
589 @c ---------------------------------------------------------------------
591 @c ---------------------------------------------------------------------
594 @chapter Runtime: Influencing runtime behavior with environment variables
595 @cindex environment variable
597 The behavior of the @command{gfortran} can be influenced by
598 environment variables.
600 Malformed environment variables are silently ignored.
603 * TMPDIR:: Directory for scratch files
604 * GFORTRAN_STDIN_UNIT:: Unit number for standard input
605 * GFORTRAN_STDOUT_UNIT:: Unit number for standard output
606 * GFORTRAN_STDERR_UNIT:: Unit number for standard error
607 * GFORTRAN_UNBUFFERED_ALL:: Do not buffer I/O for all units.
608 * GFORTRAN_UNBUFFERED_PRECONNECTED:: Do not buffer I/O for preconnected units.
609 * GFORTRAN_SHOW_LOCUS:: Show location for runtime errors
610 * GFORTRAN_OPTIONAL_PLUS:: Print leading + where permitted
611 * GFORTRAN_LIST_SEPARATOR:: Separator for list output
612 * GFORTRAN_CONVERT_UNIT:: Set endianness for unformatted I/O
613 * GFORTRAN_ERROR_BACKTRACE:: Show backtrace on run-time errors
614 * GFORTRAN_FORMATTED_BUFFER_SIZE:: Buffer size for formatted files.
615 * GFORTRAN_UNFORMATTED_BUFFER_SIZE:: Buffer size for unformatted files.
619 @section @env{TMPDIR}---Directory for scratch files
621 When opening a file with @code{STATUS='SCRATCH'}, GNU Fortran tries to
622 create the file in one of the potential directories by testing each
623 directory in the order below.
627 The environment variable @env{TMPDIR}, if it exists.
630 On the MinGW target, the directory returned by the @code{GetTempPath}
631 function. Alternatively, on the Cygwin target, the @env{TMP} and
632 @env{TEMP} environment variables, if they exist, in that order.
635 The @code{P_tmpdir} macro if it is defined, otherwise the directory
639 @node GFORTRAN_STDIN_UNIT
640 @section @env{GFORTRAN_STDIN_UNIT}---Unit number for standard input
642 This environment variable can be used to select the unit number
643 preconnected to standard input. This must be a positive integer.
644 The default value is 5.
646 @node GFORTRAN_STDOUT_UNIT
647 @section @env{GFORTRAN_STDOUT_UNIT}---Unit number for standard output
649 This environment variable can be used to select the unit number
650 preconnected to standard output. This must be a positive integer.
651 The default value is 6.
653 @node GFORTRAN_STDERR_UNIT
654 @section @env{GFORTRAN_STDERR_UNIT}---Unit number for standard error
656 This environment variable can be used to select the unit number
657 preconnected to standard error. This must be a positive integer.
658 The default value is 0.
660 @node GFORTRAN_UNBUFFERED_ALL
661 @section @env{GFORTRAN_UNBUFFERED_ALL}---Do not buffer I/O on all units
663 This environment variable controls whether all I/O is unbuffered. If
664 the first letter is @samp{y}, @samp{Y} or @samp{1}, all I/O is
665 unbuffered. This will slow down small sequential reads and writes. If
666 the first letter is @samp{n}, @samp{N} or @samp{0}, I/O is buffered.
669 @node GFORTRAN_UNBUFFERED_PRECONNECTED
670 @section @env{GFORTRAN_UNBUFFERED_PRECONNECTED}---Do not buffer I/O on preconnected units
672 The environment variable named @env{GFORTRAN_UNBUFFERED_PRECONNECTED} controls
673 whether I/O on a preconnected unit (i.e.@: STDOUT or STDERR) is unbuffered. If
674 the first letter is @samp{y}, @samp{Y} or @samp{1}, I/O is unbuffered. This
675 will slow down small sequential reads and writes. If the first letter
676 is @samp{n}, @samp{N} or @samp{0}, I/O is buffered. This is the default.
678 @node GFORTRAN_SHOW_LOCUS
679 @section @env{GFORTRAN_SHOW_LOCUS}---Show location for runtime errors
681 If the first letter is @samp{y}, @samp{Y} or @samp{1}, filename and
682 line numbers for runtime errors are printed. If the first letter is
683 @samp{n}, @samp{N} or @samp{0}, do not print filename and line numbers
684 for runtime errors. The default is to print the location.
686 @node GFORTRAN_OPTIONAL_PLUS
687 @section @env{GFORTRAN_OPTIONAL_PLUS}---Print leading + where permitted
689 If the first letter is @samp{y}, @samp{Y} or @samp{1},
690 a plus sign is printed
691 where permitted by the Fortran standard. If the first letter
692 is @samp{n}, @samp{N} or @samp{0}, a plus sign is not printed
693 in most cases. Default is not to print plus signs.
695 @node GFORTRAN_LIST_SEPARATOR
696 @section @env{GFORTRAN_LIST_SEPARATOR}---Separator for list output
698 This environment variable specifies the separator when writing
699 list-directed output. It may contain any number of spaces and
700 at most one comma. If you specify this on the command line,
701 be sure to quote spaces, as in
703 $ GFORTRAN_LIST_SEPARATOR=' , ' ./a.out
705 when @command{a.out} is the compiled Fortran program that you want to run.
706 Default is a single space.
708 @node GFORTRAN_CONVERT_UNIT
709 @section @env{GFORTRAN_CONVERT_UNIT}---Set endianness for unformatted I/O
711 By setting the @env{GFORTRAN_CONVERT_UNIT} variable, it is possible
712 to change the representation of data for unformatted files.
713 The syntax for the @env{GFORTRAN_CONVERT_UNIT} variable is:
715 GFORTRAN_CONVERT_UNIT: mode | mode ';' exception | exception ;
716 mode: 'native' | 'swap' | 'big_endian' | 'little_endian' ;
717 exception: mode ':' unit_list | unit_list ;
718 unit_list: unit_spec | unit_list unit_spec ;
719 unit_spec: INTEGER | INTEGER '-' INTEGER ;
721 The variable consists of an optional default mode, followed by
722 a list of optional exceptions, which are separated by semicolons
723 from the preceding default and each other. Each exception consists
724 of a format and a comma-separated list of units. Valid values for
725 the modes are the same as for the @code{CONVERT} specifier:
728 @item @code{NATIVE} Use the native format. This is the default.
729 @item @code{SWAP} Swap between little- and big-endian.
730 @item @code{LITTLE_ENDIAN} Use the little-endian format
731 for unformatted files.
732 @item @code{BIG_ENDIAN} Use the big-endian format for unformatted files.
734 A missing mode for an exception is taken to mean @code{BIG_ENDIAN}.
735 Examples of values for @env{GFORTRAN_CONVERT_UNIT} are:
737 @item @code{'big_endian'} Do all unformatted I/O in big_endian mode.
738 @item @code{'little_endian;native:10-20,25'} Do all unformatted I/O
739 in little_endian mode, except for units 10 to 20 and 25, which are in
741 @item @code{'10-20'} Units 10 to 20 are big-endian, the rest is native.
744 Setting the environment variables should be done on the command
745 line or via the @command{export}
746 command for @command{sh}-compatible shells and via @command{setenv}
747 for @command{csh}-compatible shells.
749 Example for @command{sh}:
752 $ GFORTRAN_CONVERT_UNIT='big_endian;native:10-20' ./a.out
755 Example code for @command{csh}:
758 % setenv GFORTRAN_CONVERT_UNIT 'big_endian;native:10-20'
762 Using anything but the native representation for unformatted data
763 carries a significant speed overhead. If speed in this area matters
764 to you, it is best if you use this only for data that needs to be
767 @xref{CONVERT specifier}, for an alternative way to specify the
768 data representation for unformatted files. @xref{Runtime Options}, for
769 setting a default data representation for the whole program. The
770 @code{CONVERT} specifier overrides the @option{-fconvert} compile options.
772 @emph{Note that the values specified via the GFORTRAN_CONVERT_UNIT
773 environment variable will override the CONVERT specifier in the
774 open statement}. This is to give control over data formats to
775 users who do not have the source code of their program available.
777 @node GFORTRAN_ERROR_BACKTRACE
778 @section @env{GFORTRAN_ERROR_BACKTRACE}---Show backtrace on run-time errors
780 If the @env{GFORTRAN_ERROR_BACKTRACE} variable is set to @samp{y},
781 @samp{Y} or @samp{1} (only the first letter is relevant) then a
782 backtrace is printed when a serious run-time error occurs. To disable
783 the backtracing, set the variable to @samp{n}, @samp{N}, @samp{0}.
784 Default is to print a backtrace unless the @option{-fno-backtrace}
785 compile option was used.
787 @node GFORTRAN_FORMATTED_BUFFER_SIZE
788 @section @env{GFORTRAN_FORMATTED_BUFFER_SIZE}---Set buffer size for formatted I/O
790 The @env{GFORTRAN_FORMATTED_BUFFER_SIZE} environment variable
791 specifies buffer size in bytes to be used for formatted output.
792 The default value is 8192.
794 @node GFORTRAN_UNFORMATTED_BUFFER_SIZE
795 @section @env{GFORTRAN_UNFORMATTED_BUFFER_SIZE}---Set buffer size for unformatted I/O
797 The @env{GFORTRAN_UNFORMATTED_BUFFER_SIZE} environment variable
798 specifies buffer size in bytes to be used for unformatted output.
799 The default value is 131072.
801 @c =====================================================================
802 @c PART II: LANGUAGE REFERENCE
803 @c =====================================================================
806 \part{II}{Language Reference}
809 @c ---------------------------------------------------------------------
810 @c Fortran standards status
811 @c ---------------------------------------------------------------------
813 @node Fortran standards status
814 @chapter Fortran standards status
817 * Fortran 2003 status::
818 * Fortran 2008 status::
819 * Fortran 2018 status::
822 @node Fortran 2003 status
823 @section Fortran 2003 status
825 GNU Fortran supports several Fortran 2003 features; an incomplete
826 list can be found below. See also the
827 @uref{https://gcc.gnu.org/wiki/Fortran2003, wiki page} about Fortran 2003.
830 @item Procedure pointers including procedure-pointer components with
831 @code{PASS} attribute.
833 @item Procedures which are bound to a derived type (type-bound procedures)
834 including @code{PASS}, @code{PROCEDURE} and @code{GENERIC}, and
835 operators bound to a type.
837 @item Abstract interfaces and type extension with the possibility to
838 override type-bound procedures or to have deferred binding.
840 @item Polymorphic entities (``@code{CLASS}'') for derived types and unlimited
841 polymorphism (``@code{CLASS(*)}'') -- including @code{SAME_TYPE_AS},
842 @code{EXTENDS_TYPE_OF} and @code{SELECT TYPE} for scalars and arrays and
845 @item Generic interface names, which have the same name as derived types,
846 are now supported. This allows one to write constructor functions. Note
847 that Fortran does not support static constructor functions. For static
848 variables, only default initialization or structure-constructor
849 initialization are available.
851 @item The @code{ASSOCIATE} construct.
853 @item Interoperability with C including enumerations,
855 @item In structure constructors the components with default values may be
858 @item Extensions to the @code{ALLOCATE} statement, allowing for a
859 type-specification with type parameter and for allocation and initialization
860 from a @code{SOURCE=} expression; @code{ALLOCATE} and @code{DEALLOCATE}
861 optionally return an error message string via @code{ERRMSG=}.
863 @item Reallocation on assignment: If an intrinsic assignment is
864 used, an allocatable variable on the left-hand side is automatically allocated
865 (if unallocated) or reallocated (if the shape is different). Currently, scalar
866 deferred character length left-hand sides are correctly handled but arrays
867 are not yet fully implemented.
869 @item Deferred-length character variables and scalar deferred-length character
870 components of derived types are supported. (Note that array-valued compoents
871 are not yet implemented.)
873 @item Transferring of allocations via @code{MOVE_ALLOC}.
875 @item The @code{PRIVATE} and @code{PUBLIC} attributes may be given individually
876 to derived-type components.
878 @item In pointer assignments, the lower bound may be specified and
879 the remapping of elements is supported.
881 @item For pointers an @code{INTENT} may be specified which affect the
882 association status not the value of the pointer target.
884 @item Intrinsics @code{command_argument_count}, @code{get_command},
885 @code{get_command_argument}, and @code{get_environment_variable}.
887 @item Support for Unicode characters (ISO 10646) and UTF-8, including
888 the @code{SELECTED_CHAR_KIND} and @code{NEW_LINE} intrinsic functions.
890 @item Support for binary, octal and hexadecimal (BOZ) constants in the
891 intrinsic functions @code{INT}, @code{REAL}, @code{CMPLX} and @code{DBLE}.
893 @item Support for namelist variables with allocatable and pointer
894 attribute and nonconstant length type parameter.
897 @cindex array, constructors
899 Array constructors using square brackets. That is, @code{[...]} rather
900 than @code{(/.../)}. Type-specification for array constructors like
901 @code{(/ some-type :: ... /)}.
903 @item Extensions to the specification and initialization expressions,
904 including the support for intrinsics with real and complex arguments.
906 @item Support for the asynchronous input/output.
909 @cindex @code{FLUSH} statement
910 @cindex statement, @code{FLUSH}
911 @code{FLUSH} statement.
914 @cindex @code{IOMSG=} specifier
915 @code{IOMSG=} specifier for I/O statements.
918 @cindex @code{ENUM} statement
919 @cindex @code{ENUMERATOR} statement
920 @cindex statement, @code{ENUM}
921 @cindex statement, @code{ENUMERATOR}
922 @opindex @code{fshort-enums}
923 Support for the declaration of enumeration constants via the
924 @code{ENUM} and @code{ENUMERATOR} statements. Interoperability with
925 @command{gcc} is guaranteed also for the case where the
926 @command{-fshort-enums} command line option is given.
933 @cindex @code{ALLOCATABLE} dummy arguments
934 @code{ALLOCATABLE} dummy arguments.
936 @cindex @code{ALLOCATABLE} function results
937 @code{ALLOCATABLE} function results
939 @cindex @code{ALLOCATABLE} components of derived types
940 @code{ALLOCATABLE} components of derived types
944 @cindex @code{STREAM} I/O
945 @cindex @code{ACCESS='STREAM'} I/O
946 The @code{OPEN} statement supports the @code{ACCESS='STREAM'} specifier,
947 allowing I/O without any record structure.
950 Namelist input/output for internal files.
952 @item Minor I/O features: Rounding during formatted output, using of
953 a decimal comma instead of a decimal point, setting whether a plus sign
954 should appear for positive numbers. On systems where @code{strtod} honours
955 the rounding mode, the rounding mode is also supported for input.
958 @cindex @code{PROTECTED} statement
959 @cindex statement, @code{PROTECTED}
960 The @code{PROTECTED} statement and attribute.
963 @cindex @code{VALUE} statement
964 @cindex statement, @code{VALUE}
965 The @code{VALUE} statement and attribute.
968 @cindex @code{VOLATILE} statement
969 @cindex statement, @code{VOLATILE}
970 The @code{VOLATILE} statement and attribute.
973 @cindex @code{IMPORT} statement
974 @cindex statement, @code{IMPORT}
975 The @code{IMPORT} statement, allowing to import
976 host-associated derived types.
978 @item The intrinsic modules @code{ISO_FORTRAN_ENVIRONMENT} is supported,
979 which contains parameters of the I/O units, storage sizes. Additionally,
980 procedures for C interoperability are available in the @code{ISO_C_BINDING}
984 @cindex @code{USE, INTRINSIC} statement
985 @cindex statement, @code{USE, INTRINSIC}
986 @cindex @code{ISO_FORTRAN_ENV} statement
987 @cindex statement, @code{ISO_FORTRAN_ENV}
988 @code{USE} statement with @code{INTRINSIC} and @code{NON_INTRINSIC}
989 attribute; supported intrinsic modules: @code{ISO_FORTRAN_ENV},
990 @code{ISO_C_BINDING}, @code{OMP_LIB} and @code{OMP_LIB_KINDS},
994 Renaming of operators in the @code{USE} statement.
999 @node Fortran 2008 status
1000 @section Fortran 2008 status
1002 The latest version of the Fortran standard is ISO/IEC 1539-1:2010, informally
1003 known as Fortran 2008. The official version is available from International
1004 Organization for Standardization (ISO) or its national member organizations.
1005 The the final draft (FDIS) can be downloaded free of charge from
1006 @url{http://www.nag.co.uk/@/sc22wg5/@/links.html}. Fortran is developed by the
1007 Working Group 5 of Sub-Committee 22 of the Joint Technical Committee 1 of the
1008 International Organization for Standardization and the International
1009 Electrotechnical Commission (IEC). This group is known as
1010 @uref{http://www.nag.co.uk/sc22wg5/, WG5}.
1012 The GNU Fortran compiler supports several of the new features of Fortran 2008;
1013 the @uref{https://gcc.gnu.org/wiki/Fortran2008Status, wiki} has some information
1014 about the current Fortran 2008 implementation status. In particular, the
1015 following is implemented.
1018 @item The @option{-std=f2008} option and support for the file extensions
1019 @file{.f08} and @file{.F08}.
1021 @item The @code{OPEN} statement now supports the @code{NEWUNIT=} option,
1022 which returns a unique file unit, thus preventing inadvertent use of the
1023 same unit in different parts of the program.
1025 @item The @code{g0} format descriptor and unlimited format items.
1027 @item The mathematical intrinsics @code{ASINH}, @code{ACOSH}, @code{ATANH},
1028 @code{ERF}, @code{ERFC}, @code{GAMMA}, @code{LOG_GAMMA}, @code{BESSEL_J0},
1029 @code{BESSEL_J1}, @code{BESSEL_JN}, @code{BESSEL_Y0}, @code{BESSEL_Y1},
1030 @code{BESSEL_YN}, @code{HYPOT}, @code{NORM2}, and @code{ERFC_SCALED}.
1032 @item Using complex arguments with @code{TAN}, @code{SINH}, @code{COSH},
1033 @code{TANH}, @code{ASIN}, @code{ACOS}, and @code{ATAN} is now possible;
1034 @code{ATAN}(@var{Y},@var{X}) is now an alias for @code{ATAN2}(@var{Y},@var{X}).
1036 @item Support of the @code{PARITY} intrinsic functions.
1038 @item The following bit intrinsics: @code{LEADZ} and @code{TRAILZ} for
1039 counting the number of leading and trailing zero bits, @code{POPCNT} and
1040 @code{POPPAR} for counting the number of one bits and returning the parity;
1041 @code{BGE}, @code{BGT}, @code{BLE}, and @code{BLT} for bitwise comparisons;
1042 @code{DSHIFTL} and @code{DSHIFTR} for combined left and right shifts,
1043 @code{MASKL} and @code{MASKR} for simple left and right justified masks,
1044 @code{MERGE_BITS} for a bitwise merge using a mask, @code{SHIFTA},
1045 @code{SHIFTL} and @code{SHIFTR} for shift operations, and the
1046 transformational bit intrinsics @code{IALL}, @code{IANY} and @code{IPARITY}.
1048 @item Support of the @code{EXECUTE_COMMAND_LINE} intrinsic subroutine.
1050 @item Support for the @code{STORAGE_SIZE} intrinsic inquiry function.
1052 @item The @code{INT@{8,16,32@}} and @code{REAL@{32,64,128@}} kind type
1053 parameters and the array-valued named constants @code{INTEGER_KINDS},
1054 @code{LOGICAL_KINDS}, @code{REAL_KINDS} and @code{CHARACTER_KINDS} of
1055 the intrinsic module @code{ISO_FORTRAN_ENV}.
1057 @item The module procedures @code{C_SIZEOF} of the intrinsic module
1058 @code{ISO_C_BINDINGS} and @code{COMPILER_VERSION} and @code{COMPILER_OPTIONS}
1059 of @code{ISO_FORTRAN_ENV}.
1061 @item Coarray support for serial programs with @option{-fcoarray=single} flag
1062 and experimental support for multiple images with the @option{-fcoarray=lib}
1065 @item Submodules are supported. It should noted that @code{MODULEs} do not
1066 produce the smod file needed by the descendent @code{SUBMODULEs} unless they
1067 contain at least one @code{MODULE PROCEDURE} interface. The reason for this is
1068 that @code{SUBMODULEs} are useless without @code{MODULE PROCEDUREs}. See
1069 http://j3-fortran.org/doc/meeting/207/15-209.txt for a discussion and a draft
1070 interpretation. Adopting this interpretation has the advantage that code that
1071 does not use submodules does not generate smod files.
1073 @item The @code{DO CONCURRENT} construct is supported.
1075 @item The @code{BLOCK} construct is supported.
1077 @item The @code{STOP} and the new @code{ERROR STOP} statements now
1078 support all constant expressions. Both show the signals which were signaling
1081 @item Support for the @code{CONTIGUOUS} attribute.
1083 @item Support for @code{ALLOCATE} with @code{MOLD}.
1085 @item Support for the @code{IMPURE} attribute for procedures, which
1086 allows for @code{ELEMENTAL} procedures without the restrictions of
1089 @item Null pointers (including @code{NULL()}) and not-allocated variables
1090 can be used as actual argument to optional non-pointer, non-allocatable
1091 dummy arguments, denoting an absent argument.
1093 @item Non-pointer variables with @code{TARGET} attribute can be used as
1094 actual argument to @code{POINTER} dummies with @code{INTENT(IN)}.
1096 @item Pointers including procedure pointers and those in a derived
1097 type (pointer components) can now be initialized by a target instead
1098 of only by @code{NULL}.
1100 @item The @code{EXIT} statement (with construct-name) can be now be
1101 used to leave not only the @code{DO} but also the @code{ASSOCIATE},
1102 @code{BLOCK}, @code{IF}, @code{SELECT CASE} and @code{SELECT TYPE}
1105 @item Internal procedures can now be used as actual argument.
1107 @item Minor features: obsolesce diagnostics for @code{ENTRY} with
1108 @option{-std=f2008}; a line may start with a semicolon; for internal
1109 and module procedures @code{END} can be used instead of
1110 @code{END SUBROUTINE} and @code{END FUNCTION}; @code{SELECTED_REAL_KIND}
1111 now also takes a @code{RADIX} argument; intrinsic types are supported
1112 for @code{TYPE}(@var{intrinsic-type-spec}); multiple type-bound procedures
1113 can be declared in a single @code{PROCEDURE} statement; implied-shape
1114 arrays are supported for named constants (@code{PARAMETER}).
1119 @node Fortran 2018 status
1120 @section Status of Fortran 2018 support
1123 @item ERROR STOP in a PURE procedure
1124 An @code{ERROR STOP} statement is permitted in a @code{PURE}
1127 @item IMPLICIT NONE with a spec-list
1128 Support the @code{IMPLICIT NONE} statement with an
1129 @code{implicit-none-spec-list}.
1131 @item Behavior of INQUIRE with the RECL= specifier
1133 The behavior of the @code{INQUIRE} statement with the @code{RECL=}
1134 specifier now conforms to Fortran 2018.
1139 @subsection TS 29113 Status (Further Interoperability with C)
1141 GNU Fortran supports some of the new features of the Technical
1142 Specification (TS) 29113 on Further Interoperability of Fortran with C.
1143 The @uref{https://gcc.gnu.org/wiki/TS29113Status, wiki} has some information
1144 about the current TS 29113 implementation status. In particular, the
1145 following is implemented.
1147 See also @ref{Further Interoperability of Fortran with C}.
1150 @item The @code{OPTIONAL} attribute is allowed for dummy arguments
1151 of @code{BIND(C) procedures.}
1153 @item The @code{RANK} intrinsic is supported.
1155 @item GNU Fortran's implementation for variables with @code{ASYNCHRONOUS}
1156 attribute is compatible with TS 29113.
1158 @item Assumed types (@code{TYPE(*)}).
1160 @item Assumed-rank (@code{DIMENSION(..)}).
1162 @item ISO_Fortran_binding (now in Fortran 2018 18.4) is implemented such that
1163 conversion of the array descriptor for assumed type or assumed rank arrays is
1164 done in the library. The include file ISO_Fortran_binding.h is can be found in
1165 @code{~prefix/lib/gcc/$target/$version}.
1170 @subsection TS 18508 Status (Additional Parallel Features)
1172 GNU Fortran supports the following new features of the Technical
1173 Specification 18508 on Additional Parallel Features in Fortran:
1176 @item The new atomic ADD, CAS, FETCH and ADD/OR/XOR, OR and XOR intrinsics.
1178 @item The @code{CO_MIN} and @code{CO_MAX} and @code{SUM} reduction intrinsics.
1179 And the @code{CO_BROADCAST} and @code{CO_REDUCE} intrinsic, except that those
1180 do not support polymorphic types or types with allocatable, pointer or
1181 polymorphic components.
1183 @item Events (@code{EVENT POST}, @code{EVENT WAIT}, @code{EVENT_QUERY})
1185 @item Failed images (@code{FAIL IMAGE}, @code{IMAGE_STATUS},
1186 @code{FAILED_IMAGES}, @code{STOPPED_IMAGES})
1191 @c ---------------------------------------------------------------------
1192 @c Compiler Characteristics
1193 @c ---------------------------------------------------------------------
1195 @node Compiler Characteristics
1196 @chapter Compiler Characteristics
1198 This chapter describes certain characteristics of the GNU Fortran
1199 compiler, that are not specified by the Fortran standard, but which
1200 might in some way or another become visible to the programmer.
1203 * KIND Type Parameters::
1204 * Internal representation of LOGICAL variables::
1205 * Evaluation of logical expressions::
1206 * MAX and MIN intrinsics with REAL NaN arguments::
1207 * Thread-safety of the runtime library::
1208 * Data consistency and durability::
1209 * Files opened without an explicit ACTION= specifier::
1210 * File operations on symbolic links::
1211 * File format of unformatted sequential files::
1212 * Asynchronous I/O::
1216 @node KIND Type Parameters
1217 @section KIND Type Parameters
1220 The @code{KIND} type parameters supported by GNU Fortran for the primitive
1226 1, 2, 4, 8*, 16*, default: 4**
1229 1, 2, 4, 8*, 16*, default: 4**
1232 4, 8, 10*, 16*, default: 4***
1235 4, 8, 10*, 16*, default: 4***
1237 @item DOUBLE PRECISION
1238 4, 8, 10*, 16*, default: 8***
1246 * not available on all systems @*
1247 ** unless @option{-fdefault-integer-8} is used @*
1248 *** unless @option{-fdefault-real-8} is used (see @ref{Fortran Dialect Options})
1251 The @code{KIND} value matches the storage size in bytes, except for
1252 @code{COMPLEX} where the storage size is twice as much (or both real and
1253 imaginary part are a real value of the given size). It is recommended to use
1254 the @ref{SELECTED_CHAR_KIND}, @ref{SELECTED_INT_KIND} and
1255 @ref{SELECTED_REAL_KIND} intrinsics or the @code{INT8}, @code{INT16},
1256 @code{INT32}, @code{INT64}, @code{REAL32}, @code{REAL64}, and @code{REAL128}
1257 parameters of the @code{ISO_FORTRAN_ENV} module instead of the concrete values.
1258 The available kind parameters can be found in the constant arrays
1259 @code{CHARACTER_KINDS}, @code{INTEGER_KINDS}, @code{LOGICAL_KINDS} and
1260 @code{REAL_KINDS} in the @ref{ISO_FORTRAN_ENV} module. For C interoperability,
1261 the kind parameters of the @ref{ISO_C_BINDING} module should be used.
1264 @node Internal representation of LOGICAL variables
1265 @section Internal representation of LOGICAL variables
1266 @cindex logical, variable representation
1268 The Fortran standard does not specify how variables of @code{LOGICAL}
1269 type are represented, beyond requiring that @code{LOGICAL} variables
1270 of default kind have the same storage size as default @code{INTEGER}
1271 and @code{REAL} variables. The GNU Fortran internal representation is
1274 A @code{LOGICAL(KIND=N)} variable is represented as an
1275 @code{INTEGER(KIND=N)} variable, however, with only two permissible
1276 values: @code{1} for @code{.TRUE.} and @code{0} for
1277 @code{.FALSE.}. Any other integer value results in undefined behavior.
1279 See also @ref{Argument passing conventions} and @ref{Interoperability with C}.
1282 @node Evaluation of logical expressions
1283 @section Evaluation of logical expressions
1285 The Fortran standard does not require the compiler to evaluate all parts of an
1286 expression, if they do not contribute to the final result. For logical
1287 expressions with @code{.AND.} or @code{.OR.} operators, in particular, GNU
1288 Fortran will optimize out function calls (even to impure functions) if the
1289 result of the expression can be established without them. However, since not
1290 all compilers do that, and such an optimization can potentially modify the
1291 program flow and subsequent results, GNU Fortran throws warnings for such
1292 situations with the @option{-Wfunction-elimination} flag.
1295 @node MAX and MIN intrinsics with REAL NaN arguments
1296 @section MAX and MIN intrinsics with REAL NaN arguments
1297 @cindex MAX, MIN, NaN
1299 The Fortran standard does not specify what the result of the
1300 @code{MAX} and @code{MIN} intrinsics are if one of the arguments is a
1301 @code{NaN}. Accordingly, the GNU Fortran compiler does not specify
1302 that either, as this allows for faster and more compact code to be
1303 generated. If the programmer wishes to take some specific action in
1304 case one of the arguments is a @code{NaN}, it is necessary to
1305 explicitly test the arguments before calling @code{MAX} or @code{MIN},
1306 e.g. with the @code{IEEE_IS_NAN} function from the intrinsic module
1307 @code{IEEE_ARITHMETIC}.
1310 @node Thread-safety of the runtime library
1311 @section Thread-safety of the runtime library
1312 @cindex thread-safety, threads
1314 GNU Fortran can be used in programs with multiple threads, e.g.@: by
1315 using OpenMP, by calling OS thread handling functions via the
1316 @code{ISO_C_BINDING} facility, or by GNU Fortran compiled library code
1317 being called from a multi-threaded program.
1319 The GNU Fortran runtime library, (@code{libgfortran}), supports being
1320 called concurrently from multiple threads with the following
1323 During library initialization, the C @code{getenv} function is used,
1324 which need not be thread-safe. Similarly, the @code{getenv}
1325 function is used to implement the @code{GET_ENVIRONMENT_VARIABLE} and
1326 @code{GETENV} intrinsics. It is the responsibility of the user to
1327 ensure that the environment is not being updated concurrently when any
1328 of these actions are taking place.
1330 The @code{EXECUTE_COMMAND_LINE} and @code{SYSTEM} intrinsics are
1331 implemented with the @code{system} function, which need not be
1332 thread-safe. It is the responsibility of the user to ensure that
1333 @code{system} is not called concurrently.
1335 For platforms not supporting thread-safe POSIX functions, further
1336 functionality might not be thread-safe. For details, please consult
1337 the documentation for your operating system.
1339 The GNU Fortran runtime library uses various C library functions that
1340 depend on the locale, such as @code{strtod} and @code{snprintf}. In
1341 order to work correctly in locale-aware programs that set the locale
1342 using @code{setlocale}, the locale is reset to the default ``C''
1343 locale while executing a formatted @code{READ} or @code{WRITE}
1344 statement. On targets supporting the POSIX 2008 per-thread locale
1345 functions (e.g. @code{newlocale}, @code{uselocale},
1346 @code{freelocale}), these are used and thus the global locale set
1347 using @code{setlocale} or the per-thread locales in other threads are
1348 not affected. However, on targets lacking this functionality, the
1349 global LC_NUMERIC locale is set to ``C'' during the formatted I/O.
1350 Thus, on such targets it's not safe to call @code{setlocale}
1351 concurrently from another thread while a Fortran formatted I/O
1352 operation is in progress. Also, other threads doing something
1353 dependent on the LC_NUMERIC locale might not work correctly if a
1354 formatted I/O operation is in progress in another thread.
1356 @node Data consistency and durability
1357 @section Data consistency and durability
1358 @cindex consistency, durability
1360 This section contains a brief overview of data and metadata
1361 consistency and durability issues when doing I/O.
1363 With respect to durability, GNU Fortran makes no effort to ensure that
1364 data is committed to stable storage. If this is required, the GNU
1365 Fortran programmer can use the intrinsic @code{FNUM} to retrieve the
1366 low level file descriptor corresponding to an open Fortran unit. Then,
1367 using e.g. the @code{ISO_C_BINDING} feature, one can call the
1368 underlying system call to flush dirty data to stable storage, such as
1369 @code{fsync} on POSIX, @code{_commit} on MingW, or @code{fcntl(fd,
1370 F_FULLSYNC, 0)} on Mac OS X. The following example shows how to call
1374 ! Declare the interface for POSIX fsync function
1376 function fsync (fd) bind(c,name="fsync")
1377 use iso_c_binding, only: c_int
1378 integer(c_int), value :: fd
1379 integer(c_int) :: fsync
1383 ! Variable declaration
1387 open (10,file="foo")
1390 ! Perform I/O on unit 10
1395 ret = fsync(fnum(10))
1397 ! Handle possible error
1398 if (ret /= 0) stop "Error calling FSYNC"
1401 With respect to consistency, for regular files GNU Fortran uses
1402 buffered I/O in order to improve performance. This buffer is flushed
1403 automatically when full and in some other situations, e.g. when
1404 closing a unit. It can also be explicitly flushed with the
1405 @code{FLUSH} statement. Also, the buffering can be turned off with the
1406 @code{GFORTRAN_UNBUFFERED_ALL} and
1407 @code{GFORTRAN_UNBUFFERED_PRECONNECTED} environment variables. Special
1408 files, such as terminals and pipes, are always unbuffered. Sometimes,
1409 however, further things may need to be done in order to allow other
1410 processes to see data that GNU Fortran has written, as follows.
1412 The Windows platform supports a relaxed metadata consistency model,
1413 where file metadata is written to the directory lazily. This means
1414 that, for instance, the @code{dir} command can show a stale size for a
1415 file. One can force a directory metadata update by closing the unit,
1416 or by calling @code{_commit} on the file descriptor. Note, though,
1417 that @code{_commit} will force all dirty data to stable storage, which
1418 is often a very slow operation.
1420 The Network File System (NFS) implements a relaxed consistency model
1421 called open-to-close consistency. Closing a file forces dirty data and
1422 metadata to be flushed to the server, and opening a file forces the
1423 client to contact the server in order to revalidate cached
1424 data. @code{fsync} will also force a flush of dirty data and metadata
1425 to the server. Similar to @code{open} and @code{close}, acquiring and
1426 releasing @code{fcntl} file locks, if the server supports them, will
1427 also force cache validation and flushing dirty data and metadata.
1430 @node Files opened without an explicit ACTION= specifier
1431 @section Files opened without an explicit ACTION= specifier
1432 @cindex open, action
1434 The Fortran standard says that if an @code{OPEN} statement is executed
1435 without an explicit @code{ACTION=} specifier, the default value is
1436 processor dependent. GNU Fortran behaves as follows:
1439 @item Attempt to open the file with @code{ACTION='READWRITE'}
1440 @item If that fails, try to open with @code{ACTION='READ'}
1441 @item If that fails, try to open with @code{ACTION='WRITE'}
1442 @item If that fails, generate an error
1446 @node File operations on symbolic links
1447 @section File operations on symbolic links
1448 @cindex file, symbolic link
1450 This section documents the behavior of GNU Fortran for file operations on
1451 symbolic links, on systems that support them.
1455 @item Results of INQUIRE statements of the ``inquire by file'' form will
1456 relate to the target of the symbolic link. For example,
1457 @code{INQUIRE(FILE="foo",EXIST=ex)} will set @var{ex} to @var{.true.} if
1458 @var{foo} is a symbolic link pointing to an existing file, and @var{.false.}
1459 if @var{foo} points to an non-existing file (``dangling'' symbolic link).
1461 @item Using the @code{OPEN} statement with a @code{STATUS="NEW"} specifier
1462 on a symbolic link will result in an error condition, whether the symbolic
1463 link points to an existing target or is dangling.
1465 @item If a symbolic link was connected, using the @code{CLOSE} statement
1466 with a @code{STATUS="DELETE"} specifier will cause the symbolic link itself
1467 to be deleted, not its target.
1471 @node File format of unformatted sequential files
1472 @section File format of unformatted sequential files
1473 @cindex file, unformatted sequential
1474 @cindex unformatted sequential
1475 @cindex sequential, unformatted
1476 @cindex record marker
1479 Unformatted sequential files are stored as logical records using
1480 record markers. Each logical record consists of one of more
1483 Each subrecord consists of a leading record marker, the data written
1484 by the user program, and a trailing record marker. The record markers
1485 are four-byte integers by default, and eight-byte integers if the
1486 @option{-fmax-subrecord-length=8} option (which exists for backwards
1487 compability only) is in effect.
1489 The representation of the record markers is that of unformatted files
1490 given with the @option{-fconvert} option, the @ref{CONVERT specifier}
1491 in an open statement or the @ref{GFORTRAN_CONVERT_UNIT} environment
1494 The maximum number of bytes of user data in a subrecord is 2147483639
1495 (2 GiB - 9) for a four-byte record marker. This limit can be lowered
1496 with the @option{-fmax-subrecord-length} option, altough this is
1497 rarely useful. If the length of a logical record exceeds this limit,
1498 the data is distributed among several subrecords.
1500 The absolute of the number stored in the record markers is the number
1501 of bytes of user data in the corresponding subrecord. If the leading
1502 record marker of a subrecord contains a negative number, another
1503 subrecord follows the current one. If the trailing record marker
1504 contains a negative number, then there is a preceding subrecord.
1506 In the most simple case, with only one subrecord per logical record,
1507 both record markers contain the number of bytes of user data in the
1510 The format for unformatted sequential data can be duplicated using
1511 unformatted stream, as shown in the example program for an unformatted
1512 record containing a single subrecord:
1516 use iso_fortran_env, only: int32
1519 real, dimension(10) :: a, b
1520 call random_number(a)
1521 open (10,file='test.dat',form='unformatted',access='stream')
1522 inquire (iolength=i) a
1525 open (10,file='test.dat',form='unformatted')
1527 if (all (a == b)) print *,'success!'
1531 @node Asynchronous I/O
1532 @section Asynchronous I/O
1533 @cindex input/output, asynchronous
1534 @cindex asynchronous I/O
1536 Asynchronous I/O is supported if the program is linked against the
1537 POSIX thread library. If that is not the case, all I/O is performed
1538 as synchronous. On systems which do not support pthread condition
1539 variables, such as AIX, I/O is also performed as synchronous.
1541 On some systems, such as Darwin or Solaris, the POSIX thread library
1542 is always linked in, so asynchronous I/O is always performed. On other
1543 sytems, such as Linux, it is necessary to specify @option{-pthread},
1544 @option{-lpthread} or @option{-fopenmp} during the linking step.
1546 @c ---------------------------------------------------------------------
1548 @c ---------------------------------------------------------------------
1550 @c Maybe this chapter should be merged with the 'Standards' section,
1551 @c whenever that is written :-)
1557 The two sections below detail the extensions to standard Fortran that are
1558 implemented in GNU Fortran, as well as some of the popular or
1559 historically important extensions that are not (or not yet) implemented.
1560 For the latter case, we explain the alternatives available to GNU Fortran
1561 users, including replacement by standard-conforming code or GNU
1565 * Extensions implemented in GNU Fortran::
1566 * Extensions not implemented in GNU Fortran::
1570 @node Extensions implemented in GNU Fortran
1571 @section Extensions implemented in GNU Fortran
1572 @cindex extensions, implemented
1574 GNU Fortran implements a number of extensions over standard Fortran.
1575 This chapter contains information on their syntax and meaning. There
1576 are currently two categories of GNU Fortran extensions, those that
1577 provide functionality beyond that provided by any standard, and those
1578 that are supported by GNU Fortran purely for backward compatibility
1579 with legacy compilers. By default, @option{-std=gnu} allows the
1580 compiler to accept both types of extensions, but to warn about the use
1581 of the latter. Specifying either @option{-std=f95},
1582 @option{-std=f2003}, @option{-std=f2008}, or @option{-std=f2018}
1583 disables both types of extensions, and @option{-std=legacy} allows
1584 both without warning. The special compile flag @option{-fdec} enables
1585 additional compatibility extensions along with those enabled by
1586 @option{-std=legacy}.
1589 * Old-style kind specifications::
1590 * Old-style variable initialization::
1591 * Extensions to namelist::
1592 * X format descriptor without count field::
1593 * Commas in FORMAT specifications::
1594 * Missing period in FORMAT specifications::
1595 * Default widths for F@comma{} G and I format descriptors::
1597 * @code{Q} exponent-letter::
1598 * BOZ literal constants::
1599 * Real array indices::
1601 * Implicitly convert LOGICAL and INTEGER values::
1602 * Hollerith constants support::
1604 * CONVERT specifier::
1607 * Argument list functions::
1608 * Read/Write after EOF marker::
1609 * STRUCTURE and RECORD::
1611 * Type variants for integer intrinsics::
1612 * AUTOMATIC and STATIC attributes::
1613 * Extended math intrinsics::
1614 * Form feed as whitespace::
1615 * TYPE as an alias for PRINT::
1616 * %LOC as an rvalue::
1618 * Bitwise logical operators::
1619 * Extended I/O specifiers::
1620 * Legacy PARAMETER statements::
1621 * Default exponents::
1624 @node Old-style kind specifications
1625 @subsection Old-style kind specifications
1626 @cindex kind, old-style
1628 GNU Fortran allows old-style kind specifications in declarations. These
1634 where @code{TYPESPEC} is a basic type (@code{INTEGER}, @code{REAL},
1635 etc.), and where @code{size} is a byte count corresponding to the
1636 storage size of a valid kind for that type. (For @code{COMPLEX}
1637 variables, @code{size} is the total size of the real and imaginary
1638 parts.) The statement then declares @code{x}, @code{y} and @code{z} to
1639 be of type @code{TYPESPEC} with the appropriate kind. This is
1640 equivalent to the standard-conforming declaration
1645 where @code{k} is the kind parameter suitable for the intended precision. As
1646 kind parameters are implementation-dependent, use the @code{KIND},
1647 @code{SELECTED_INT_KIND} and @code{SELECTED_REAL_KIND} intrinsics to retrieve
1648 the correct value, for instance @code{REAL*8 x} can be replaced by:
1650 INTEGER, PARAMETER :: dbl = KIND(1.0d0)
1654 @node Old-style variable initialization
1655 @subsection Old-style variable initialization
1657 GNU Fortran allows old-style initialization of variables of the
1661 REAL x(2,2) /3*0.,1./
1663 The syntax for the initializers is as for the @code{DATA} statement, but
1664 unlike in a @code{DATA} statement, an initializer only applies to the
1665 variable immediately preceding the initialization. In other words,
1666 something like @code{INTEGER I,J/2,3/} is not valid. This style of
1667 initialization is only allowed in declarations without double colons
1668 (@code{::}); the double colons were introduced in Fortran 90, which also
1669 introduced a standard syntax for initializing variables in type
1672 Examples of standard-conforming code equivalent to the above example
1676 INTEGER :: i = 1, j = 2
1677 REAL :: x(2,2) = RESHAPE((/0.,0.,0.,1./),SHAPE(x))
1681 DATA i/1/, j/2/, x/3*0.,1./
1684 Note that variables which are explicitly initialized in declarations
1685 or in @code{DATA} statements automatically acquire the @code{SAVE}
1688 @node Extensions to namelist
1689 @subsection Extensions to namelist
1692 GNU Fortran fully supports the Fortran 95 standard for namelist I/O
1693 including array qualifiers, substrings and fully qualified derived types.
1694 The output from a namelist write is compatible with namelist read. The
1695 output has all names in upper case and indentation to column 1 after the
1696 namelist name. Two extensions are permitted:
1698 Old-style use of @samp{$} instead of @samp{&}
1701 X(:)%Y(2) = 1.0 2.0 3.0
1706 It should be noted that the default terminator is @samp{/} rather than
1709 Querying of the namelist when inputting from stdin. After at least
1710 one space, entering @samp{?} sends to stdout the namelist name and the names of
1711 the variables in the namelist:
1722 Entering @samp{=?} outputs the namelist to stdout, as if
1723 @code{WRITE(*,NML = mynml)} had been called:
1728 X(1)%Y= 0.000000 , 1.000000 , 0.000000 ,
1729 X(2)%Y= 0.000000 , 2.000000 , 0.000000 ,
1730 X(3)%Y= 0.000000 , 3.000000 , 0.000000 ,
1734 To aid this dialog, when input is from stdin, errors send their
1735 messages to stderr and execution continues, even if @code{IOSTAT} is set.
1737 @code{PRINT} namelist is permitted. This causes an error if
1738 @option{-std=f95} is used.
1741 REAL, dimension (4) :: x = (/1.0, 2.0, 3.0, 4.0/)
1744 END PROGRAM test_print
1747 Expanded namelist reads are permitted. This causes an error if
1748 @option{-std=f95} is used. In the following example, the first element
1749 of the array will be given the value 0.00 and the two succeeding
1750 elements will be given the values 1.00 and 2.00.
1753 X(1,1) = 0.00 , 1.00 , 2.00
1757 When writing a namelist, if no @code{DELIM=} is specified, by default a
1758 double quote is used to delimit character strings. If -std=F95, F2003,
1759 or F2008, etc, the delim status is set to 'none'. Defaulting to
1760 quotes ensures that namelists with character strings can be subsequently
1761 read back in accurately.
1763 @node X format descriptor without count field
1764 @subsection @code{X} format descriptor without count field
1766 To support legacy codes, GNU Fortran permits the count field of the
1767 @code{X} edit descriptor in @code{FORMAT} statements to be omitted.
1768 When omitted, the count is implicitly assumed to be one.
1772 10 FORMAT (I1, X, I1)
1775 @node Commas in FORMAT specifications
1776 @subsection Commas in @code{FORMAT} specifications
1778 To support legacy codes, GNU Fortran allows the comma separator
1779 to be omitted immediately before and after character string edit
1780 descriptors in @code{FORMAT} statements. A comma with no following format
1781 decriptor is permited if the @option{-fdec-blank-format-item} is given on
1782 the command line. This is considered non-conforming code and is
1787 10 FORMAT ('FOO='I1' BAR='I2)
1793 @node Missing period in FORMAT specifications
1794 @subsection Missing period in @code{FORMAT} specifications
1796 To support legacy codes, GNU Fortran allows missing periods in format
1797 specifications if and only if @option{-std=legacy} is given on the
1798 command line. This is considered non-conforming code and is
1807 @node Default widths for F@comma{} G and I format descriptors
1808 @subsection Default widths for @code{F}, @code{G} and @code{I} format descriptors
1810 To support legacy codes, GNU Fortran allows width to be omitted from format
1811 specifications if and only if @option{-fdec-format-defaults} is given on the
1812 command line. Default widths will be used. This is considered non-conforming
1813 code and is discouraged.
1818 WRITE(*,10) value1, value1, value2
1819 10 FORMAT ('F, G, I')
1823 @node I/O item lists
1824 @subsection I/O item lists
1825 @cindex I/O item lists
1827 To support legacy codes, GNU Fortran allows the input item list
1828 of the @code{READ} statement, and the output item lists of the
1829 @code{WRITE} and @code{PRINT} statements, to start with a comma.
1831 @node @code{Q} exponent-letter
1832 @subsection @code{Q} exponent-letter
1833 @cindex @code{Q} exponent-letter
1835 GNU Fortran accepts real literal constants with an exponent-letter
1836 of @code{Q}, for example, @code{1.23Q45}. The constant is interpreted
1837 as a @code{REAL(16)} entity on targets that support this type. If
1838 the target does not support @code{REAL(16)} but has a @code{REAL(10)}
1839 type, then the real-literal-constant will be interpreted as a
1840 @code{REAL(10)} entity. In the absence of @code{REAL(16)} and
1841 @code{REAL(10)}, an error will occur.
1843 @node BOZ literal constants
1844 @subsection BOZ literal constants
1845 @cindex BOZ literal constants
1847 Besides decimal constants, Fortran also supports binary (@code{b}),
1848 octal (@code{o}) and hexadecimal (@code{z}) integer constants. The
1849 syntax is: @samp{prefix quote digits quote}, were the prefix is
1850 either @code{b}, @code{o} or @code{z}, quote is either @code{'} or
1851 @code{"} and the digits are @code{0} or @code{1} for binary,
1852 between @code{0} and @code{7} for octal, and between @code{0} and
1853 @code{F} for hexadecimal. (Example: @code{b'01011101'}.)
1855 Up to Fortran 95, BOZ literal constants were only allowed to initialize
1856 integer variables in DATA statements. Since Fortran 2003 BOZ literal
1857 constants are also allowed as actual arguments to the @code{REAL},
1858 @code{DBLE}, @code{INT} and @code{CMPLX} intrinsic functions.
1859 The BOZ literal constant is simply a string of bits, which is padded
1860 or truncated as needed, during conversion to a numeric type. The
1861 Fortran standard states that the treatment of the sign bit is processor
1862 dependent. Gfortran interprets the sign bit as a user would expect.
1864 As a deprecated extension, GNU Fortran allows hexadecimal BOZ literal
1865 constants to be specified using the @code{X} prefix. The BOZ literal
1866 constant can also be specified by adding a suffix to the string, for
1867 example, @code{Z'ABC'} and @code{'ABC'X} are equivalent.
1869 @node Real array indices
1870 @subsection Real array indices
1871 @cindex array, indices of type real
1873 As an extension, GNU Fortran allows the use of @code{REAL} expressions
1874 or variables as array indices.
1876 @node Unary operators
1877 @subsection Unary operators
1878 @cindex operators, unary
1880 As an extension, GNU Fortran allows unary plus and unary minus operators
1881 to appear as the second operand of binary arithmetic operators without
1882 the need for parenthesis.
1888 @node Implicitly convert LOGICAL and INTEGER values
1889 @subsection Implicitly convert @code{LOGICAL} and @code{INTEGER} values
1890 @cindex conversion, to integer
1891 @cindex conversion, to logical
1893 As an extension for backwards compatibility with other compilers, GNU
1894 Fortran allows the implicit conversion of @code{LOGICAL} values to
1895 @code{INTEGER} values and vice versa. When converting from a
1896 @code{LOGICAL} to an @code{INTEGER}, @code{.FALSE.} is interpreted as
1897 zero, and @code{.TRUE.} is interpreted as one. When converting from
1898 @code{INTEGER} to @code{LOGICAL}, the value zero is interpreted as
1899 @code{.FALSE.} and any nonzero value is interpreted as @code{.TRUE.}.
1910 However, there is no implicit conversion of @code{INTEGER} values in
1911 @code{if}-statements, nor of @code{LOGICAL} or @code{INTEGER} values
1914 @node Hollerith constants support
1915 @subsection Hollerith constants support
1916 @cindex Hollerith constants
1918 GNU Fortran supports Hollerith constants in assignments, function
1919 arguments, and @code{DATA} statements. A Hollerith constant is written
1920 as a string of characters preceded by an integer constant indicating the
1921 character count, and the letter @code{H} or @code{h}, and stored in
1922 bytewise fashion in a numeric (@code{INTEGER}, @code{REAL}, or
1923 @code{COMPLEX}) or @code{LOGICAL} variable. The constant will be padded
1924 with spaces or truncated to fit the size of the variable in which it is
1927 Examples of valid uses of Hollerith constants:
1930 data x /16Habcdefghijklmnop, 16Hqrstuvwxyz012345/
1931 x(1) = 16HABCDEFGHIJKLMNOP
1935 Examples of Hollerith constants:
1938 a = 0H ! Invalid, at least one character is needed.
1940 a = 8H12345678 ! Valid, but the Hollerith constant will be truncated.
1941 a = 3Hxyz ! Valid, but the Hollerith constant will be padded.
1944 In general, Hollerith constants were used to provide a rudimentary
1945 facility for handling character strings in early Fortran compilers,
1946 prior to the introduction of @code{CHARACTER} variables in Fortran 77;
1947 in those cases, the standard-compliant equivalent is to convert the
1948 program to use proper character strings. On occasion, there may be a
1949 case where the intent is specifically to initialize a numeric variable
1950 with a given byte sequence. In these cases, the same result can be
1951 obtained by using the @code{TRANSFER} statement, as in this example.
1953 INTEGER(KIND=4) :: a
1954 a = TRANSFER ("abcd", a) ! equivalent to: a = 4Habcd
1959 @subsection Cray pointers
1960 @cindex pointer, Cray
1962 Cray pointers are part of a non-standard extension that provides a
1963 C-like pointer in Fortran. This is accomplished through a pair of
1964 variables: an integer "pointer" that holds a memory address, and a
1965 "pointee" that is used to dereference the pointer.
1967 Pointer/pointee pairs are declared in statements of the form:
1969 pointer ( <pointer> , <pointee> )
1973 pointer ( <pointer1> , <pointee1> ), ( <pointer2> , <pointee2> ), ...
1975 The pointer is an integer that is intended to hold a memory address.
1976 The pointee may be an array or scalar.
1977 If an assumed-size array is permitted within the scoping unit, a
1978 pointee can be an assumed-size array.
1979 That is, the last dimension may be left unspecified by using a @code{*}
1980 in place of a value. A pointee cannot be an assumed shape array.
1981 No space is allocated for the pointee.
1983 The pointee may have its type declared before or after the pointer
1984 statement, and its array specification (if any) may be declared
1985 before, during, or after the pointer statement. The pointer may be
1986 declared as an integer prior to the pointer statement. However, some
1987 machines have default integer sizes that are different than the size
1988 of a pointer, and so the following code is not portable:
1993 If a pointer is declared with a kind that is too small, the compiler
1994 will issue a warning; the resulting binary will probably not work
1995 correctly, because the memory addresses stored in the pointers may be
1996 truncated. It is safer to omit the first line of the above example;
1997 if explicit declaration of ipt's type is omitted, then the compiler
1998 will ensure that ipt is an integer variable large enough to hold a
2001 Pointer arithmetic is valid with Cray pointers, but it is not the same
2002 as C pointer arithmetic. Cray pointers are just ordinary integers, so
2003 the user is responsible for determining how many bytes to add to a
2004 pointer in order to increment it. Consider the following example:
2008 pointer (ipt, pointee)
2012 The last statement does not set @code{ipt} to the address of
2013 @code{target(1)}, as it would in C pointer arithmetic. Adding @code{1}
2014 to @code{ipt} just adds one byte to the address stored in @code{ipt}.
2016 Any expression involving the pointee will be translated to use the
2017 value stored in the pointer as the base address.
2019 To get the address of elements, this extension provides an intrinsic
2020 function @code{LOC()}. The @code{LOC()} function is equivalent to the
2021 @code{&} operator in C, except the address is cast to an integer type:
2024 pointer(ipt, arpte(10))
2026 ipt = loc(ar) ! Makes arpte is an alias for ar
2027 arpte(1) = 1.0 ! Sets ar(1) to 1.0
2029 The pointer can also be set by a call to the @code{MALLOC} intrinsic
2032 Cray pointees often are used to alias an existing variable. For
2040 As long as @code{ipt} remains unchanged, @code{iarr} is now an alias for
2041 @code{target}. The optimizer, however, will not detect this aliasing, so
2042 it is unsafe to use @code{iarr} and @code{target} simultaneously. Using
2043 a pointee in any way that violates the Fortran aliasing rules or
2044 assumptions is illegal. It is the user's responsibility to avoid doing
2045 this; the compiler works under the assumption that no such aliasing
2048 Cray pointers will work correctly when there is no aliasing (i.e., when
2049 they are used to access a dynamically allocated block of memory), and
2050 also in any routine where a pointee is used, but any variable with which
2051 it shares storage is not used. Code that violates these rules may not
2052 run as the user intends. This is not a bug in the optimizer; any code
2053 that violates the aliasing rules is illegal. (Note that this is not
2054 unique to GNU Fortran; any Fortran compiler that supports Cray pointers
2055 will ``incorrectly'' optimize code with illegal aliasing.)
2057 There are a number of restrictions on the attributes that can be applied
2058 to Cray pointers and pointees. Pointees may not have the
2059 @code{ALLOCATABLE}, @code{INTENT}, @code{OPTIONAL}, @code{DUMMY},
2060 @code{TARGET}, @code{INTRINSIC}, or @code{POINTER} attributes. Pointers
2061 may not have the @code{DIMENSION}, @code{POINTER}, @code{TARGET},
2062 @code{ALLOCATABLE}, @code{EXTERNAL}, or @code{INTRINSIC} attributes, nor
2063 may they be function results. Pointees may not occur in more than one
2064 pointer statement. A pointee cannot be a pointer. Pointees cannot occur
2065 in equivalence, common, or data statements.
2067 A Cray pointer may also point to a function or a subroutine. For
2068 example, the following excerpt is valid:
2072 pointer (subptr,subpte)
2082 A pointer may be modified during the course of a program, and this
2083 will change the location to which the pointee refers. However, when
2084 pointees are passed as arguments, they are treated as ordinary
2085 variables in the invoked function. Subsequent changes to the pointer
2086 will not change the base address of the array that was passed.
2088 @node CONVERT specifier
2089 @subsection @code{CONVERT} specifier
2090 @cindex @code{CONVERT} specifier
2092 GNU Fortran allows the conversion of unformatted data between little-
2093 and big-endian representation to facilitate moving of data
2094 between different systems. The conversion can be indicated with
2095 the @code{CONVERT} specifier on the @code{OPEN} statement.
2096 @xref{GFORTRAN_CONVERT_UNIT}, for an alternative way of specifying
2097 the data format via an environment variable.
2099 Valid values for @code{CONVERT} are:
2101 @item @code{CONVERT='NATIVE'} Use the native format. This is the default.
2102 @item @code{CONVERT='SWAP'} Swap between little- and big-endian.
2103 @item @code{CONVERT='LITTLE_ENDIAN'} Use the little-endian representation
2104 for unformatted files.
2105 @item @code{CONVERT='BIG_ENDIAN'} Use the big-endian representation for
2109 Using the option could look like this:
2111 open(file='big.dat',form='unformatted',access='sequential', &
2112 convert='big_endian')
2115 The value of the conversion can be queried by using
2116 @code{INQUIRE(CONVERT=ch)}. The values returned are
2117 @code{'BIG_ENDIAN'} and @code{'LITTLE_ENDIAN'}.
2119 @code{CONVERT} works between big- and little-endian for
2120 @code{INTEGER} values of all supported kinds and for @code{REAL}
2121 on IEEE systems of kinds 4 and 8. Conversion between different
2122 ``extended double'' types on different architectures such as
2123 m68k and x86_64, which GNU Fortran
2124 supports as @code{REAL(KIND=10)} and @code{REAL(KIND=16)}, will
2127 @emph{Note that the values specified via the GFORTRAN_CONVERT_UNIT
2128 environment variable will override the CONVERT specifier in the
2129 open statement}. This is to give control over data formats to
2130 users who do not have the source code of their program available.
2132 Using anything but the native representation for unformatted data
2133 carries a significant speed overhead. If speed in this area matters
2134 to you, it is best if you use this only for data that needs to be
2141 OpenMP (Open Multi-Processing) is an application programming
2142 interface (API) that supports multi-platform shared memory
2143 multiprocessing programming in C/C++ and Fortran on many
2144 architectures, including Unix and Microsoft Windows platforms.
2145 It consists of a set of compiler directives, library routines,
2146 and environment variables that influence run-time behavior.
2148 GNU Fortran strives to be compatible to the
2149 @uref{http://openmp.org/wp/openmp-specifications/,
2150 OpenMP Application Program Interface v4.5}.
2152 To enable the processing of the OpenMP directive @code{!$omp} in
2153 free-form source code; the @code{c$omp}, @code{*$omp} and @code{!$omp}
2154 directives in fixed form; the @code{!$} conditional compilation sentinels
2155 in free form; and the @code{c$}, @code{*$} and @code{!$} sentinels
2156 in fixed form, @command{gfortran} needs to be invoked with the
2157 @option{-fopenmp}. This also arranges for automatic linking of the
2158 GNU Offloading and Multi Processing Runtime Library
2159 @ref{Top,,libgomp,libgomp,GNU Offloading and Multi Processing Runtime
2162 The OpenMP Fortran runtime library routines are provided both in a
2163 form of a Fortran 90 module named @code{omp_lib} and in a form of
2164 a Fortran @code{include} file named @file{omp_lib.h}.
2166 An example of a parallelized loop taken from Appendix A.1 of
2167 the OpenMP Application Program Interface v2.5:
2169 SUBROUTINE A1(N, A, B)
2172 !$OMP PARALLEL DO !I is private by default
2174 B(I) = (A(I) + A(I-1)) / 2.0
2176 !$OMP END PARALLEL DO
2183 @option{-fopenmp} implies @option{-frecursive}, i.e., all local arrays
2184 will be allocated on the stack. When porting existing code to OpenMP,
2185 this may lead to surprising results, especially to segmentation faults
2186 if the stacksize is limited.
2189 On glibc-based systems, OpenMP enabled applications cannot be statically
2190 linked due to limitations of the underlying pthreads-implementation. It
2191 might be possible to get a working solution if
2192 @command{-Wl,--whole-archive -lpthread -Wl,--no-whole-archive} is added
2193 to the command line. However, this is not supported by @command{gcc} and
2194 thus not recommended.
2201 OpenACC is an application programming interface (API) that supports
2202 offloading of code to accelerator devices. It consists of a set of
2203 compiler directives, library routines, and environment variables that
2204 influence run-time behavior.
2206 GNU Fortran strives to be compatible to the
2207 @uref{http://www.openacc.org/, OpenACC Application Programming
2210 To enable the processing of the OpenACC directive @code{!$acc} in
2211 free-form source code; the @code{c$acc}, @code{*$acc} and @code{!$acc}
2212 directives in fixed form; the @code{!$} conditional compilation
2213 sentinels in free form; and the @code{c$}, @code{*$} and @code{!$}
2214 sentinels in fixed form, @command{gfortran} needs to be invoked with
2215 the @option{-fopenacc}. This also arranges for automatic linking of
2216 the GNU Offloading and Multi Processing Runtime Library
2217 @ref{Top,,libgomp,libgomp,GNU Offloading and Multi Processing Runtime
2220 The OpenACC Fortran runtime library routines are provided both in a
2221 form of a Fortran 90 module named @code{openacc} and in a form of a
2222 Fortran @code{include} file named @file{openacc_lib.h}.
2224 Note that this is an experimental feature, incomplete, and subject to
2225 change in future versions of GCC. See
2226 @uref{https://gcc.gnu.org/wiki/OpenACC} for more information.
2228 @node Argument list functions
2229 @subsection Argument list functions @code{%VAL}, @code{%REF} and @code{%LOC}
2230 @cindex argument list functions
2235 GNU Fortran supports argument list functions @code{%VAL}, @code{%REF}
2236 and @code{%LOC} statements, for backward compatibility with g77.
2237 It is recommended that these should be used only for code that is
2238 accessing facilities outside of GNU Fortran, such as operating system
2239 or windowing facilities. It is best to constrain such uses to isolated
2240 portions of a program--portions that deal specifically and exclusively
2241 with low-level, system-dependent facilities. Such portions might well
2242 provide a portable interface for use by the program as a whole, but are
2243 themselves not portable, and should be thoroughly tested each time they
2244 are rebuilt using a new compiler or version of a compiler.
2246 @code{%VAL} passes a scalar argument by value, @code{%REF} passes it by
2247 reference and @code{%LOC} passes its memory location. Since gfortran
2248 already passes scalar arguments by reference, @code{%REF} is in effect
2249 a do-nothing. @code{%LOC} has the same effect as a Fortran pointer.
2251 An example of passing an argument by value to a C subroutine foo.:
2254 C prototype void foo_ (float x);
2263 For details refer to the g77 manual
2264 @uref{https://gcc.gnu.org/@/onlinedocs/@/gcc-3.4.6/@/g77/@/index.html#Top}.
2266 Also, @code{c_by_val.f} and its partner @code{c_by_val.c} of the
2267 GNU Fortran testsuite are worth a look.
2269 @node Read/Write after EOF marker
2270 @subsection Read/Write after EOF marker
2272 @cindex @code{BACKSPACE}
2273 @cindex @code{REWIND}
2275 Some legacy codes rely on allowing @code{READ} or @code{WRITE} after the
2276 EOF file marker in order to find the end of a file. GNU Fortran normally
2277 rejects these codes with a run-time error message and suggests the user
2278 consider @code{BACKSPACE} or @code{REWIND} to properly position
2279 the file before the EOF marker. As an extension, the run-time error may
2280 be disabled using -std=legacy.
2283 @node STRUCTURE and RECORD
2284 @subsection @code{STRUCTURE} and @code{RECORD}
2285 @cindex @code{STRUCTURE}
2286 @cindex @code{RECORD}
2288 Record structures are a pre-Fortran-90 vendor extension to create
2289 user-defined aggregate data types. Support for record structures in GNU
2290 Fortran can be enabled with the @option{-fdec-structure} compile flag.
2291 If you have a choice, you should instead use Fortran 90's ``derived types'',
2292 which have a different syntax.
2294 In many cases, record structures can easily be converted to derived types.
2295 To convert, replace @code{STRUCTURE /}@var{structure-name}@code{/}
2296 by @code{TYPE} @var{type-name}. Additionally, replace
2297 @code{RECORD /}@var{structure-name}@code{/} by
2298 @code{TYPE(}@var{type-name}@code{)}. Finally, in the component access,
2299 replace the period (@code{.}) by the percent sign (@code{%}).
2301 Here is an example of code using the non portable record structure syntax:
2304 ! Declaring a structure named ``item'' and containing three fields:
2305 ! an integer ID, an description string and a floating-point price.
2308 CHARACTER(LEN=200) description
2312 ! Define two variables, an single record of type ``item''
2313 ! named ``pear'', and an array of items named ``store_catalog''
2314 RECORD /item/ pear, store_catalog(100)
2316 ! We can directly access the fields of both variables
2318 pear.description = "juicy D'Anjou pear"
2320 store_catalog(7).id = 7831
2321 store_catalog(7).description = "milk bottle"
2322 store_catalog(7).price = 1.2
2324 ! We can also manipulate the whole structure
2325 store_catalog(12) = pear
2326 print *, store_catalog(12)
2330 This code can easily be rewritten in the Fortran 90 syntax as following:
2333 ! ``STRUCTURE /name/ ... END STRUCTURE'' becomes
2334 ! ``TYPE name ... END TYPE''
2337 CHARACTER(LEN=200) description
2341 ! ``RECORD /name/ variable'' becomes ``TYPE(name) variable''
2342 TYPE(item) pear, store_catalog(100)
2344 ! Instead of using a dot (.) to access fields of a record, the
2345 ! standard syntax uses a percent sign (%)
2347 pear%description = "juicy D'Anjou pear"
2349 store_catalog(7)%id = 7831
2350 store_catalog(7)%description = "milk bottle"
2351 store_catalog(7)%price = 1.2
2353 ! Assignments of a whole variable do not change
2354 store_catalog(12) = pear
2355 print *, store_catalog(12)
2359 GNU Fortran implements STRUCTURES like derived types with the following
2360 rules and exceptions:
2363 @item Structures act like derived types with the @code{SEQUENCE} attribute.
2364 Otherwise they may contain no specifiers.
2366 @item Structures may contain a special field with the name @code{%FILL}.
2367 This will create an anonymous component which cannot be accessed but occupies
2368 space just as if a component of the same type was declared in its place, useful
2369 for alignment purposes. As an example, the following structure will consist
2370 of at least sixteen bytes:
2380 @item Structures may share names with other symbols. For example, the following
2381 is invalid for derived types, but valid for structures:
2387 record /header/ header
2390 @item Structure types may be declared nested within another parent structure.
2393 structure /type-name/
2395 structure [/<type-name>/] <field-list>
2399 The type name may be ommitted, in which case the structure type itself is
2400 anonymous, and other structures of the same type cannot be instantiated. The
2401 following shows some examples:
2404 structure /appointment/
2405 ! nested structure definition: app_time is an array of two 'time'
2406 structure /time/ app_time (2)
2407 integer(1) hour, minute
2412 ! The 'time' structure is still usable
2418 structure /appointment/
2419 ! anonymous nested structure definition
2420 structure start, end
2421 integer(1) hour, minute
2427 @item Structures may contain @code{UNION} blocks. For more detail see the
2428 section on @ref{UNION and MAP}.
2430 @item Structures support old-style initialization of components, like
2431 those described in @ref{Old-style variable initialization}. For array
2432 initializers, an initializer may contain a repeat specification of the form
2433 @code{<literal-integer> * <constant-initializer>}. The value of the integer
2434 indicates the number of times to repeat the constant initializer when expanding
2435 the initializer list.
2439 @subsection @code{UNION} and @code{MAP}
2440 @cindex @code{UNION}
2443 Unions are an old vendor extension which were commonly used with the
2444 non-standard @ref{STRUCTURE and RECORD} extensions. Use of @code{UNION} and
2445 @code{MAP} is automatically enabled with @option{-fdec-structure}.
2447 A @code{UNION} declaration occurs within a structure; within the definition of
2448 each union is a number of @code{MAP} blocks. Each @code{MAP} shares storage
2449 with its sibling maps (in the same union), and the size of the union is the
2450 size of the largest map within it, just as with unions in C. The major
2451 difference is that component references do not indicate which union or map the
2452 component is in (the compiler gets to figure that out).
2454 Here is a small example:
2459 character(2) w0, w1, w2
2467 record /myunion/ rec
2468 ! After this assignment...
2471 ! The following is true:
2477 The two maps share memory, and the size of the union is ultimately six bytes:
2480 0 1 2 3 4 5 6 Byte offset
2481 -------------------------------
2483 -------------------------------
2486 \-------/ \-------/ \-------/
2489 \---------------------------/
2492 Following is an example mirroring the layout of an Intel x86_64 register:
2501 character(8) rh ! rah
2504 character(8) rl ! ral
2507 character(8) ex ! eax
2510 character(4) eh ! eah
2513 character(4) el ! eal
2530 ! After this assignment...
2531 a.rx = 'AAAAAAAA.BBB.C.D'
2533 ! The following is true:
2534 a.rx === 'AAAAAAAA.BBB.C.D'
2545 @node Type variants for integer intrinsics
2546 @subsection Type variants for integer intrinsics
2547 @cindex intrinsics, integer
2549 Similar to the D/C prefixes to real functions to specify the input/output
2550 types, GNU Fortran offers B/I/J/K prefixes to integer functions for
2551 compatibility with DEC programs. The types implied by each are:
2554 @code{B} - @code{INTEGER(kind=1)}
2555 @code{I} - @code{INTEGER(kind=2)}
2556 @code{J} - @code{INTEGER(kind=4)}
2557 @code{K} - @code{INTEGER(kind=8)}
2560 GNU Fortran supports these with the flag @option{-fdec-intrinsic-ints}.
2561 Intrinsics for which prefixed versions are available and in what form are noted
2562 in @ref{Intrinsic Procedures}. The complete list of supported intrinsics is
2565 @multitable @columnfractions .2 .2 .2 .2 .2
2567 @headitem Intrinsic @tab B @tab I @tab J @tab K
2569 @item @code{@ref{ABS}}
2570 @tab @code{BABS} @tab @code{IIABS} @tab @code{JIABS} @tab @code{KIABS}
2571 @item @code{@ref{BTEST}}
2572 @tab @code{BBTEST} @tab @code{BITEST} @tab @code{BJTEST} @tab @code{BKTEST}
2573 @item @code{@ref{IAND}}
2574 @tab @code{BIAND} @tab @code{IIAND} @tab @code{JIAND} @tab @code{KIAND}
2575 @item @code{@ref{IBCLR}}
2576 @tab @code{BBCLR} @tab @code{IIBCLR} @tab @code{JIBCLR} @tab @code{KIBCLR}
2577 @item @code{@ref{IBITS}}
2578 @tab @code{BBITS} @tab @code{IIBITS} @tab @code{JIBITS} @tab @code{KIBITS}
2579 @item @code{@ref{IBSET}}
2580 @tab @code{BBSET} @tab @code{IIBSET} @tab @code{JIBSET} @tab @code{KIBSET}
2581 @item @code{@ref{IEOR}}
2582 @tab @code{BIEOR} @tab @code{IIEOR} @tab @code{JIEOR} @tab @code{KIEOR}
2583 @item @code{@ref{IOR}}
2584 @tab @code{BIOR} @tab @code{IIOR} @tab @code{JIOR} @tab @code{KIOR}
2585 @item @code{@ref{ISHFT}}
2586 @tab @code{BSHFT} @tab @code{IISHFT} @tab @code{JISHFT} @tab @code{KISHFT}
2587 @item @code{@ref{ISHFTC}}
2588 @tab @code{BSHFTC} @tab @code{IISHFTC} @tab @code{JISHFTC} @tab @code{KISHFTC}
2589 @item @code{@ref{MOD}}
2590 @tab @code{BMOD} @tab @code{IMOD} @tab @code{JMOD} @tab @code{KMOD}
2591 @item @code{@ref{NOT}}
2592 @tab @code{BNOT} @tab @code{INOT} @tab @code{JNOT} @tab @code{KNOT}
2593 @item @code{@ref{REAL}}
2594 @tab @code{--} @tab @code{FLOATI} @tab @code{FLOATJ} @tab @code{FLOATK}
2597 @node AUTOMATIC and STATIC attributes
2598 @subsection @code{AUTOMATIC} and @code{STATIC} attributes
2599 @cindex variable attributes
2600 @cindex @code{AUTOMATIC}
2601 @cindex @code{STATIC}
2603 With @option{-fdec-static} GNU Fortran supports the DEC extended attributes
2604 @code{STATIC} and @code{AUTOMATIC} to provide explicit specification of entity
2605 storage. These follow the syntax of the Fortran standard @code{SAVE} attribute.
2607 @code{STATIC} is exactly equivalent to @code{SAVE}, and specifies that
2608 an entity should be allocated in static memory. As an example, @code{STATIC}
2609 local variables will retain their values across multiple calls to a function.
2611 Entities marked @code{AUTOMATIC} will be stack automatic whenever possible.
2612 @code{AUTOMATIC} is the default for local variables smaller than
2613 @option{-fmax-stack-var-size}, unless @option{-fno-automatic} is given. This
2614 attribute overrides @option{-fno-automatic}, @option{-fmax-stack-var-size}, and
2615 blanket @code{SAVE} statements.
2622 integer, automatic :: i ! automatic variable
2623 integer x, y ! static variables
2630 integer a, b, c, x, y, z
2634 ! a, b, c, and z are automatic
2635 ! x and y are static
2639 ! Compiled with -fno-automatic
2643 ! a is automatic; b, c, and d are static
2647 @node Extended math intrinsics
2648 @subsection Extended math intrinsics
2649 @cindex intrinsics, math
2650 @cindex intrinsics, trigonometric functions
2652 GNU Fortran supports an extended list of mathematical intrinsics with the
2653 compile flag @option{-fdec-math} for compatability with legacy code.
2654 These intrinsics are described fully in @ref{Intrinsic Procedures} where it is
2655 noted that they are extensions and should be avoided whenever possible.
2657 Specifically, @option{-fdec-math} enables the @ref{COTAN} intrinsic, and
2658 trigonometric intrinsics which accept or produce values in degrees instead of
2659 radians. Here is a summary of the new intrinsics:
2661 @multitable @columnfractions .5 .5
2662 @headitem Radians @tab Degrees
2663 @item @code{@ref{ACOS}} @tab @code{@ref{ACOSD}}*
2664 @item @code{@ref{ASIN}} @tab @code{@ref{ASIND}}*
2665 @item @code{@ref{ATAN}} @tab @code{@ref{ATAND}}*
2666 @item @code{@ref{ATAN2}} @tab @code{@ref{ATAN2D}}*
2667 @item @code{@ref{COS}} @tab @code{@ref{COSD}}*
2668 @item @code{@ref{COTAN}}* @tab @code{@ref{COTAND}}*
2669 @item @code{@ref{SIN}} @tab @code{@ref{SIND}}*
2670 @item @code{@ref{TAN}} @tab @code{@ref{TAND}}*
2673 * Enabled with @option{-fdec-math}.
2675 For advanced users, it may be important to know the implementation of these
2676 functions. They are simply wrappers around the standard radian functions, which
2677 have more accurate builtin versions. These functions convert their arguments
2678 (or results) to degrees (or radians) by taking the value modulus 360 (or 2*pi)
2679 and then multiplying it by a constant radian-to-degree (or degree-to-radian)
2680 factor, as appropriate. The factor is computed at compile-time as 180/pi (or
2683 @node Form feed as whitespace
2684 @subsection Form feed as whitespace
2685 @cindex form feed whitespace
2687 Historically, legacy compilers allowed insertion of form feed characters ('\f',
2688 ASCII 0xC) at the beginning of lines for formatted output to line printers,
2689 though the Fortran standard does not mention this. GNU Fortran supports the
2690 interpretation of form feed characters in source as whitespace for
2693 @node TYPE as an alias for PRINT
2694 @subsection TYPE as an alias for PRINT
2695 @cindex type alias print
2696 For compatibility, GNU Fortran will interpret @code{TYPE} statements as
2697 @code{PRINT} statements with the flag @option{-fdec}. With this flag asserted,
2698 the following two examples are equivalent:
2701 TYPE *, 'hello world'
2705 PRINT *, 'hello world'
2708 @node %LOC as an rvalue
2709 @subsection %LOC as an rvalue
2711 Normally @code{%LOC} is allowed only in parameter lists. However the intrinsic
2712 function @code{LOC} does the same thing, and is usable as the right-hand-side of
2713 assignments. For compatibility, GNU Fortran supports the use of @code{%LOC} as
2714 an alias for the builtin @code{LOC} with @option{-std=legacy}. With this
2715 feature enabled the following two examples are equivalent:
2728 @node .XOR. operator
2729 @subsection .XOR. operator
2730 @cindex operators, xor
2732 GNU Fortran supports @code{.XOR.} as a logical operator with @code{-std=legacy}
2733 for compatibility with legacy code. @code{.XOR.} is equivalent to
2734 @code{.NEQV.}. That is, the output is true if and only if the inputs differ.
2736 @node Bitwise logical operators
2737 @subsection Bitwise logical operators
2738 @cindex logical, bitwise
2740 With @option{-fdec}, GNU Fortran relaxes the type constraints on
2741 logical operators to allow integer operands, and performs the corresponding
2742 bitwise operation instead. This flag is for compatibility only, and should be
2743 avoided in new code. Consider:
2752 In this example, compiled with @option{-fdec}, GNU Fortran will
2753 replace the @code{.AND.} operation with a call to the intrinsic
2754 @code{@ref{IAND}} function, yielding the bitwise-and of @code{i} and @code{j}.
2756 Note that this conversion will occur if at least one operand is of integral
2757 type. As a result, a logical operand will be converted to an integer when the
2758 other operand is an integer in a logical operation. In this case,
2759 @code{.TRUE.} is converted to @code{1} and @code{.FALSE.} to @code{0}.
2761 Here is the mapping of logical operator to bitwise intrinsic used with
2764 @multitable @columnfractions .25 .25 .5
2765 @headitem Operator @tab Intrinsic @tab Bitwise operation
2766 @item @code{.NOT.} @tab @code{@ref{NOT}} @tab complement
2767 @item @code{.AND.} @tab @code{@ref{IAND}} @tab intersection
2768 @item @code{.OR.} @tab @code{@ref{IOR}} @tab union
2769 @item @code{.NEQV.} @tab @code{@ref{IEOR}} @tab exclusive or
2770 @item @code{.EQV.} @tab @code{@ref{NOT}(@ref{IEOR})} @tab complement of exclusive or
2773 @node Extended I/O specifiers
2774 @subsection Extended I/O specifiers
2775 @cindex @code{CARRIAGECONTROL}
2776 @cindex @code{READONLY}
2777 @cindex @code{SHARE}
2778 @cindex @code{SHARED}
2779 @cindex @code{NOSHARED}
2780 @cindex I/O specifiers
2782 GNU Fortran supports the additional legacy I/O specifiers
2783 @code{CARRIAGECONTROL}, @code{READONLY}, and @code{SHARE} with the
2784 compile flag @option{-fdec}, for compatibility.
2787 @item CARRIAGECONTROL
2788 The @code{CARRIAGECONTROL} specifier allows a user to control line
2789 termination settings between output records for an I/O unit. The specifier has
2790 no meaning for readonly files. When @code{CARRAIGECONTROL} is specified upon
2791 opening a unit for formatted writing, the exact @code{CARRIAGECONTROL} setting
2792 determines what characters to write between output records. The syntax is:
2795 OPEN(..., CARRIAGECONTROL=cc)
2798 Where @emph{cc} is a character expression that evaluates to one of the
2801 @multitable @columnfractions .2 .8
2802 @item @code{'LIST'} @tab One line feed between records (default)
2803 @item @code{'FORTRAN'} @tab Legacy interpretation of the first character (see below)
2804 @item @code{'NONE'} @tab No separator between records
2807 With @code{CARRIAGECONTROL='FORTRAN'}, when a record is written, the first
2808 character of the input record is not written, and instead determines the output
2809 record separator as follows:
2811 @multitable @columnfractions .3 .3 .4
2812 @headitem Leading character @tab Meaning @tab Output separating character(s)
2813 @item @code{'+'} @tab Overprinting @tab Carriage return only
2814 @item @code{'-'} @tab New line @tab Line feed and carriage return
2815 @item @code{'0'} @tab Skip line @tab Two line feeds and carriage return
2816 @item @code{'1'} @tab New page @tab Form feed and carriage return
2817 @item @code{'$'} @tab Prompting @tab Line feed (no carriage return)
2818 @item @code{CHAR(0)} @tab Overprinting (no advance) @tab None
2822 The @code{READONLY} specifier may be given upon opening a unit, and is
2823 equivalent to specifying @code{ACTION='READ'}, except that the file may not be
2824 deleted on close (i.e. @code{CLOSE} with @code{STATUS="DELETE"}). The syntax
2828 @code{OPEN(..., READONLY)}
2832 The @code{SHARE} specifier allows system-level locking on a unit upon opening
2833 it for controlled access from multiple processes/threads. The @code{SHARE}
2834 specifier has several forms:
2842 Where @emph{sh} in the first form is a character expression that evaluates to
2843 a value as seen in the table below. The latter two forms are aliases
2844 for particular values of @emph{sh}:
2846 @multitable @columnfractions .3 .3 .4
2847 @headitem Explicit form @tab Short form @tab Meaning
2848 @item @code{SHARE='DENYRW'} @tab @code{NOSHARED} @tab Exclusive (write) lock
2849 @item @code{SHARE='DENYNONE'} @tab @code{SHARED} @tab Shared (read) lock
2852 In general only one process may hold an exclusive (write) lock for a given file
2853 at a time, whereas many processes may hold shared (read) locks for the same
2856 The behavior of locking may vary with your operating system. On POSIX systems,
2857 locking is implemented with @code{fcntl}. Consult your corresponding operating
2858 system's manual pages for further details. Locking via @code{SHARE=} is not
2859 supported on other systems.
2863 @node Legacy PARAMETER statements
2864 @subsection Legacy PARAMETER statements
2867 For compatibility, GNU Fortran supports legacy PARAMETER statements without
2868 parentheses with @option{-std=legacy}. A warning is emitted if used with
2869 @option{-std=gnu}, and an error is acknowledged with a real Fortran standard
2870 flag (@option{-std=f95}, etc...). These statements take the following form:
2874 parameter e = 2.718282
2879 @node Default exponents
2880 @subsection Default exponents
2883 For compatibility, GNU Fortran supports a default exponent of zero in real
2884 constants with @option{-fdec}. For example, @code{9e} would be
2885 interpreted as @code{9e0}, rather than an error.
2888 @node Extensions not implemented in GNU Fortran
2889 @section Extensions not implemented in GNU Fortran
2890 @cindex extensions, not implemented
2892 The long history of the Fortran language, its wide use and broad
2893 userbase, the large number of different compiler vendors and the lack of
2894 some features crucial to users in the first standards have lead to the
2895 existence of a number of important extensions to the language. While
2896 some of the most useful or popular extensions are supported by the GNU
2897 Fortran compiler, not all existing extensions are supported. This section
2898 aims at listing these extensions and offering advice on how best make
2899 code that uses them running with the GNU Fortran compiler.
2901 @c More can be found here:
2902 @c -- https://gcc.gnu.org/onlinedocs/gcc-3.4.6/g77/Missing-Features.html
2903 @c -- the list of Fortran and libgfortran bugs closed as WONTFIX:
2904 @c http://tinyurl.com/2u4h5y
2907 * ENCODE and DECODE statements::
2908 * Variable FORMAT expressions::
2909 @c * TYPE and ACCEPT I/O Statements::
2910 @c * DEFAULTFILE, DISPOSE and RECORDTYPE I/O specifiers::
2911 @c * Omitted arguments in procedure call::
2912 * Alternate complex function syntax::
2913 * Volatile COMMON blocks::
2914 * OPEN( ... NAME=)::
2915 * Q edit descriptor::
2918 @node ENCODE and DECODE statements
2919 @subsection @code{ENCODE} and @code{DECODE} statements
2920 @cindex @code{ENCODE}
2921 @cindex @code{DECODE}
2923 GNU Fortran does not support the @code{ENCODE} and @code{DECODE}
2924 statements. These statements are best replaced by @code{READ} and
2925 @code{WRITE} statements involving internal files (@code{CHARACTER}
2926 variables and arrays), which have been part of the Fortran standard since
2927 Fortran 77. For example, replace a code fragment like
2932 c ... Code that sets LINE
2933 DECODE (80, 9000, LINE) A, B, C
2934 9000 FORMAT (1X, 3(F10.5))
2941 CHARACTER(LEN=80) LINE
2943 c ... Code that sets LINE
2944 READ (UNIT=LINE, FMT=9000) A, B, C
2945 9000 FORMAT (1X, 3(F10.5))
2948 Similarly, replace a code fragment like
2953 c ... Code that sets A, B and C
2954 ENCODE (80, 9000, LINE) A, B, C
2955 9000 FORMAT (1X, 'OUTPUT IS ', 3(F10.5))
2962 CHARACTER(LEN=80) LINE
2964 c ... Code that sets A, B and C
2965 WRITE (UNIT=LINE, FMT=9000) A, B, C
2966 9000 FORMAT (1X, 'OUTPUT IS ', 3(F10.5))
2970 @node Variable FORMAT expressions
2971 @subsection Variable @code{FORMAT} expressions
2972 @cindex @code{FORMAT}
2974 A variable @code{FORMAT} expression is format statement which includes
2975 angle brackets enclosing a Fortran expression: @code{FORMAT(I<N>)}. GNU
2976 Fortran does not support this legacy extension. The effect of variable
2977 format expressions can be reproduced by using the more powerful (and
2978 standard) combination of internal output and string formats. For example,
2979 replace a code fragment like this:
2990 c Variable declaration
2991 CHARACTER(LEN=20) FMT
2993 c Other code here...
2995 WRITE(FMT,'("(I", I0, ")")') N+1
3003 c Variable declaration
3004 CHARACTER(LEN=20) FMT
3006 c Other code here...
3009 WRITE(6,"(I" // ADJUSTL(FMT) // ")") INT1
3013 @node Alternate complex function syntax
3014 @subsection Alternate complex function syntax
3015 @cindex Complex function
3017 Some Fortran compilers, including @command{g77}, let the user declare
3018 complex functions with the syntax @code{COMPLEX FUNCTION name*16()}, as
3019 well as @code{COMPLEX*16 FUNCTION name()}. Both are non-standard, legacy
3020 extensions. @command{gfortran} accepts the latter form, which is more
3021 common, but not the former.
3024 @node Volatile COMMON blocks
3025 @subsection Volatile @code{COMMON} blocks
3026 @cindex @code{VOLATILE}
3027 @cindex @code{COMMON}
3029 Some Fortran compilers, including @command{g77}, let the user declare
3030 @code{COMMON} with the @code{VOLATILE} attribute. This is
3031 invalid standard Fortran syntax and is not supported by
3032 @command{gfortran}. Note that @command{gfortran} accepts
3033 @code{VOLATILE} variables in @code{COMMON} blocks since revision 4.3.
3036 @node OPEN( ... NAME=)
3037 @subsection @code{OPEN( ... NAME=)}
3040 Some Fortran compilers, including @command{g77}, let the user declare
3041 @code{OPEN( ... NAME=)}. This is
3042 invalid standard Fortran syntax and is not supported by
3043 @command{gfortran}. @code{OPEN( ... NAME=)} should be replaced
3044 with @code{OPEN( ... FILE=)}.
3046 @node Q edit descriptor
3047 @subsection @code{Q} edit descriptor
3048 @cindex @code{Q} edit descriptor
3050 Some Fortran compilers provide the @code{Q} edit descriptor, which
3051 transfers the number of characters left within an input record into an
3054 A direct replacement of the @code{Q} edit descriptor is not available
3055 in @command{gfortran}. How to replicate its functionality using
3056 standard-conforming code depends on what the intent of the original
3059 Options to replace @code{Q} may be to read the whole line into a
3060 character variable and then counting the number of non-blank
3061 characters left using @code{LEN_TRIM}. Another method may be to use
3062 formatted stream, read the data up to the position where the @code{Q}
3063 descriptor occurred, use @code{INQUIRE} to get the file position,
3064 count the characters up to the next @code{NEW_LINE} and then start
3065 reading from the position marked previously.
3068 @c ---------------------------------------------------------------------
3069 @c ---------------------------------------------------------------------
3070 @c Mixed-Language Programming
3071 @c ---------------------------------------------------------------------
3073 @node Mixed-Language Programming
3074 @chapter Mixed-Language Programming
3075 @cindex Interoperability
3076 @cindex Mixed-language programming
3079 * Interoperability with C::
3080 * GNU Fortran Compiler Directives::
3081 * Non-Fortran Main Program::
3082 * Naming and argument-passing conventions::
3085 This chapter is about mixed-language interoperability, but also applies
3086 if one links Fortran code compiled by different compilers. In most cases,
3087 use of the C Binding features of the Fortran 2003 standard is sufficient,
3088 and their use is highly recommended.
3091 @node Interoperability with C
3092 @section Interoperability with C
3096 * Derived Types and struct::
3097 * Interoperable Global Variables::
3098 * Interoperable Subroutines and Functions::
3099 * Working with Pointers::
3100 * Further Interoperability of Fortran with C::
3103 Since Fortran 2003 (ISO/IEC 1539-1:2004(E)) there is a
3104 standardized way to generate procedure and derived-type
3105 declarations and global variables which are interoperable with C
3106 (ISO/IEC 9899:1999). The @code{bind(C)} attribute has been added
3107 to inform the compiler that a symbol shall be interoperable with C;
3108 also, some constraints are added. Note, however, that not
3109 all C features have a Fortran equivalent or vice versa. For instance,
3110 neither C's unsigned integers nor C's functions with variable number
3111 of arguments have an equivalent in Fortran.
3113 Note that array dimensions are reversely ordered in C and that arrays in
3114 C always start with index 0 while in Fortran they start by default with
3115 1. Thus, an array declaration @code{A(n,m)} in Fortran matches
3116 @code{A[m][n]} in C and accessing the element @code{A(i,j)} matches
3117 @code{A[j-1][i-1]}. The element following @code{A(i,j)} (C: @code{A[j-1][i-1]};
3118 assuming @math{i < n}) in memory is @code{A(i+1,j)} (C: @code{A[j-1][i]}).
3120 @node Intrinsic Types
3121 @subsection Intrinsic Types
3123 In order to ensure that exactly the same variable type and kind is used
3124 in C and Fortran, the named constants shall be used which are defined in the
3125 @code{ISO_C_BINDING} intrinsic module. That module contains named constants
3126 for kind parameters and character named constants for the escape sequences
3127 in C. For a list of the constants, see @ref{ISO_C_BINDING}.
3129 For logical types, please note that the Fortran standard only guarantees
3130 interoperability between C99's @code{_Bool} and Fortran's @code{C_Bool}-kind
3131 logicals and C99 defines that @code{true} has the value 1 and @code{false}
3132 the value 0. Using any other integer value with GNU Fortran's @code{LOGICAL}
3133 (with any kind parameter) gives an undefined result. (Passing other integer
3134 values than 0 and 1 to GCC's @code{_Bool} is also undefined, unless the
3135 integer is explicitly or implicitly casted to @code{_Bool}.)
3139 @node Derived Types and struct
3140 @subsection Derived Types and struct
3142 For compatibility of derived types with @code{struct}, one needs to use
3143 the @code{BIND(C)} attribute in the type declaration. For instance, the
3144 following type declaration
3148 TYPE, BIND(C) :: myType
3149 INTEGER(C_INT) :: i1, i2
3150 INTEGER(C_SIGNED_CHAR) :: i3
3151 REAL(C_DOUBLE) :: d1
3152 COMPLEX(C_FLOAT_COMPLEX) :: c1
3153 CHARACTER(KIND=C_CHAR) :: str(5)
3157 matches the following @code{struct} declaration in C
3162 /* Note: "char" might be signed or unsigned. */
3170 Derived types with the C binding attribute shall not have the @code{sequence}
3171 attribute, type parameters, the @code{extends} attribute, nor type-bound
3172 procedures. Every component must be of interoperable type and kind and may not
3173 have the @code{pointer} or @code{allocatable} attribute. The names of the
3174 components are irrelevant for interoperability.
3176 As there exist no direct Fortran equivalents, neither unions nor structs
3177 with bit field or variable-length array members are interoperable.
3179 @node Interoperable Global Variables
3180 @subsection Interoperable Global Variables
3182 Variables can be made accessible from C using the C binding attribute,
3183 optionally together with specifying a binding name. Those variables
3184 have to be declared in the declaration part of a @code{MODULE},
3185 be of interoperable type, and have neither the @code{pointer} nor
3186 the @code{allocatable} attribute.
3192 integer(C_INT), bind(C, name="_MyProject_flags") :: global_flag
3193 type(myType), bind(C) :: tp
3197 Here, @code{_MyProject_flags} is the case-sensitive name of the variable
3198 as seen from C programs while @code{global_flag} is the case-insensitive
3199 name as seen from Fortran. If no binding name is specified, as for
3200 @var{tp}, the C binding name is the (lowercase) Fortran binding name.
3201 If a binding name is specified, only a single variable may be after the
3202 double colon. Note of warning: You cannot use a global variable to
3203 access @var{errno} of the C library as the C standard allows it to be
3204 a macro. Use the @code{IERRNO} intrinsic (GNU extension) instead.
3206 @node Interoperable Subroutines and Functions
3207 @subsection Interoperable Subroutines and Functions
3209 Subroutines and functions have to have the @code{BIND(C)} attribute to
3210 be compatible with C. The dummy argument declaration is relatively
3211 straightforward. However, one needs to be careful because C uses
3212 call-by-value by default while Fortran behaves usually similar to
3213 call-by-reference. Furthermore, strings and pointers are handled
3214 differently. Note that in Fortran 2003 and 2008 only explicit size
3215 and assumed-size arrays are supported but not assumed-shape or
3216 deferred-shape (i.e. allocatable or pointer) arrays. However, those
3217 are allowed since the Technical Specification 29113, see
3218 @ref{Further Interoperability of Fortran with C}
3220 To pass a variable by value, use the @code{VALUE} attribute.
3221 Thus, the following C prototype
3224 @code{int func(int i, int *j)}
3227 matches the Fortran declaration
3230 integer(c_int) function func(i,j)
3231 use iso_c_binding, only: c_int
3232 integer(c_int), VALUE :: i
3236 Note that pointer arguments also frequently need the @code{VALUE} attribute,
3237 see @ref{Working with Pointers}.
3239 Strings are handled quite differently in C and Fortran. In C a string
3240 is a @code{NUL}-terminated array of characters while in Fortran each string
3241 has a length associated with it and is thus not terminated (by e.g.
3242 @code{NUL}). For example, if one wants to use the following C function,
3246 void print_C(char *string) /* equivalent: char string[] */
3248 printf("%s\n", string);
3252 to print ``Hello World'' from Fortran, one can call it using
3255 use iso_c_binding, only: C_CHAR, C_NULL_CHAR
3257 subroutine print_c(string) bind(C, name="print_C")
3258 use iso_c_binding, only: c_char
3259 character(kind=c_char) :: string(*)
3260 end subroutine print_c
3262 call print_c(C_CHAR_"Hello World"//C_NULL_CHAR)
3265 As the example shows, one needs to ensure that the
3266 string is @code{NUL} terminated. Additionally, the dummy argument
3267 @var{string} of @code{print_C} is a length-one assumed-size
3268 array; using @code{character(len=*)} is not allowed. The example
3269 above uses @code{c_char_"Hello World"} to ensure the string
3270 literal has the right type; typically the default character
3271 kind and @code{c_char} are the same and thus @code{"Hello World"}
3272 is equivalent. However, the standard does not guarantee this.
3274 The use of strings is now further illustrated using the C library
3275 function @code{strncpy}, whose prototype is
3278 char *strncpy(char *restrict s1, const char *restrict s2, size_t n);
3281 The function @code{strncpy} copies at most @var{n} characters from
3282 string @var{s2} to @var{s1} and returns @var{s1}. In the following
3283 example, we ignore the return value:
3288 character(len=30) :: str,str2
3290 ! Ignore the return value of strncpy -> subroutine
3291 ! "restrict" is always assumed if we do not pass a pointer
3292 subroutine strncpy(dest, src, n) bind(C)
3294 character(kind=c_char), intent(out) :: dest(*)
3295 character(kind=c_char), intent(in) :: src(*)
3296 integer(c_size_t), value, intent(in) :: n
3297 end subroutine strncpy
3299 str = repeat('X',30) ! Initialize whole string with 'X'
3300 call strncpy(str, c_char_"Hello World"//C_NULL_CHAR, &
3301 len(c_char_"Hello World",kind=c_size_t))
3302 print '(a)', str ! prints: "Hello WorldXXXXXXXXXXXXXXXXXXX"
3306 The intrinsic procedures are described in @ref{Intrinsic Procedures}.
3308 @node Working with Pointers
3309 @subsection Working with Pointers
3311 C pointers are represented in Fortran via the special opaque derived type
3312 @code{type(c_ptr)} (with private components). Thus one needs to
3313 use intrinsic conversion procedures to convert from or to C pointers.
3315 For some applications, using an assumed type (@code{TYPE(*)}) can be an
3316 alternative to a C pointer; see
3317 @ref{Further Interoperability of Fortran with C}.
3323 type(c_ptr) :: cptr1, cptr2
3324 integer, target :: array(7), scalar
3325 integer, pointer :: pa(:), ps
3326 cptr1 = c_loc(array(1)) ! The programmer needs to ensure that the
3327 ! array is contiguous if required by the C
3329 cptr2 = c_loc(scalar)
3330 call c_f_pointer(cptr2, ps)
3331 call c_f_pointer(cptr2, pa, shape=[7])
3334 When converting C to Fortran arrays, the one-dimensional @code{SHAPE} argument
3337 If a pointer is a dummy-argument of an interoperable procedure, it usually
3338 has to be declared using the @code{VALUE} attribute. @code{void*}
3339 matches @code{TYPE(C_PTR), VALUE}, while @code{TYPE(C_PTR)} alone
3340 matches @code{void**}.
3342 Procedure pointers are handled analogously to pointers; the C type is
3343 @code{TYPE(C_FUNPTR)} and the intrinsic conversion procedures are
3344 @code{C_F_PROCPOINTER} and @code{C_FUNLOC}.
3346 Let us consider two examples of actually passing a procedure pointer from
3347 C to Fortran and vice versa. Note that these examples are also very
3348 similar to passing ordinary pointers between both languages. First,
3349 consider this code in C:
3352 /* Procedure implemented in Fortran. */
3353 void get_values (void (*)(double));
3355 /* Call-back routine we want called from Fortran. */
3359 printf ("Number is %f.\n", x);
3362 /* Call Fortran routine and pass call-back to it. */
3366 get_values (&print_it);
3370 A matching implementation for @code{get_values} in Fortran, that correctly
3371 receives the procedure pointer from C and is able to call it, is given
3372 in the following @code{MODULE}:
3378 ! Define interface of call-back routine.
3380 SUBROUTINE callback (x)
3381 USE, INTRINSIC :: ISO_C_BINDING
3382 REAL(KIND=C_DOUBLE), INTENT(IN), VALUE :: x
3383 END SUBROUTINE callback
3388 ! Define C-bound procedure.
3389 SUBROUTINE get_values (cproc) BIND(C)
3390 USE, INTRINSIC :: ISO_C_BINDING
3391 TYPE(C_FUNPTR), INTENT(IN), VALUE :: cproc
3393 PROCEDURE(callback), POINTER :: proc
3395 ! Convert C to Fortran procedure pointer.
3396 CALL C_F_PROCPOINTER (cproc, proc)
3399 CALL proc (1.0_C_DOUBLE)
3400 CALL proc (-42.0_C_DOUBLE)
3401 CALL proc (18.12_C_DOUBLE)
3402 END SUBROUTINE get_values
3407 Next, we want to call a C routine that expects a procedure pointer argument
3408 and pass it a Fortran procedure (which clearly must be interoperable!).
3409 Again, the C function may be:
3413 call_it (int (*func)(int), int arg)
3419 It can be used as in the following Fortran code:
3423 USE, INTRINSIC :: ISO_C_BINDING
3426 ! Define interface of C function.
3428 INTEGER(KIND=C_INT) FUNCTION call_it (func, arg) BIND(C)
3429 USE, INTRINSIC :: ISO_C_BINDING
3430 TYPE(C_FUNPTR), INTENT(IN), VALUE :: func
3431 INTEGER(KIND=C_INT), INTENT(IN), VALUE :: arg
3432 END FUNCTION call_it
3437 ! Define procedure passed to C function.
3438 ! It must be interoperable!
3439 INTEGER(KIND=C_INT) FUNCTION double_it (arg) BIND(C)
3440 INTEGER(KIND=C_INT), INTENT(IN), VALUE :: arg
3441 double_it = arg + arg
3442 END FUNCTION double_it
3445 SUBROUTINE foobar ()
3446 TYPE(C_FUNPTR) :: cproc
3447 INTEGER(KIND=C_INT) :: i
3449 ! Get C procedure pointer.
3450 cproc = C_FUNLOC (double_it)
3453 DO i = 1_C_INT, 10_C_INT
3454 PRINT *, call_it (cproc, i)
3456 END SUBROUTINE foobar
3461 @node Further Interoperability of Fortran with C
3462 @subsection Further Interoperability of Fortran with C
3464 The Technical Specification ISO/IEC TS 29113:2012 on further
3465 interoperability of Fortran with C extends the interoperability support
3466 of Fortran 2003 and Fortran 2008. Besides removing some restrictions
3467 and constraints, it adds assumed-type (@code{TYPE(*)}) and assumed-rank
3468 (@code{dimension}) variables and allows for interoperability of
3469 assumed-shape, assumed-rank and deferred-shape arrays, including
3470 allocatables and pointers.
3472 Note: Currently, GNU Fortran does not use internally the array descriptor
3473 (dope vector) as specified in the Technical Specification, but uses
3474 an array descriptor with different fields. Assumed type and assumed rank
3475 formal arguments are converted in the library to the specified form. The
3476 ISO_Fortran_binding API functions (also Fortran 2018 18.4) are implemented
3477 in libgfortran. Alternatively, the Chasm Language Interoperability Tools,
3478 @url{http://chasm-interop.sourceforge.net/}, provide an interface to GNU
3479 Fortran's array descriptor.
3481 The Technical Specification adds the following new features, which
3482 are supported by GNU Fortran:
3486 @item The @code{ASYNCHRONOUS} attribute has been clarified and
3487 extended to allow its use with asynchronous communication in
3488 user-provided libraries such as in implementations of the
3489 Message Passing Interface specification.
3491 @item Many constraints have been relaxed, in particular for
3492 the @code{C_LOC} and @code{C_F_POINTER} intrinsics.
3494 @item The @code{OPTIONAL} attribute is now allowed for dummy
3495 arguments; an absent argument matches a @code{NULL} pointer.
3497 @item Assumed types (@code{TYPE(*)}) have been added, which may
3498 only be used for dummy arguments. They are unlimited polymorphic
3499 but contrary to @code{CLASS(*)} they do not contain any type
3500 information, similar to C's @code{void *} pointers. Expressions
3501 of any type and kind can be passed; thus, it can be used as
3502 replacement for @code{TYPE(C_PTR)}, avoiding the use of
3503 @code{C_LOC} in the caller.
3505 Note, however, that @code{TYPE(*)} only accepts scalar arguments,
3506 unless the @code{DIMENSION} is explicitly specified. As
3507 @code{DIMENSION(*)} only supports array (including array elements) but
3508 no scalars, it is not a full replacement for @code{C_LOC}. On the
3509 other hand, assumed-type assumed-rank dummy arguments
3510 (@code{TYPE(*), DIMENSION(..)}) allow for both scalars and arrays, but
3511 require special code on the callee side to handle the array descriptor.
3513 @item Assumed-rank arrays (@code{DIMENSION(..)}) as dummy argument
3514 allow that scalars and arrays of any rank can be passed as actual
3515 argument. As the Technical Specification does not provide for direct
3516 means to operate with them, they have to be used either from the C side
3517 or be converted using @code{C_LOC} and @code{C_F_POINTER} to scalars
3518 or arrays of a specific rank. The rank can be determined using the
3519 @code{RANK} intrinisic.
3523 Currently unimplemented:
3527 @item GNU Fortran always uses an array descriptor, which does not
3528 match the one of the Technical Specification. The
3529 @code{ISO_Fortran_binding.h} header file and the C functions it
3530 specifies are not available.
3532 @item Using assumed-shape, assumed-rank and deferred-shape arrays in
3533 @code{BIND(C)} procedures is not fully supported. In particular,
3534 C interoperable strings of other length than one are not supported
3535 as this requires the new array descriptor.
3539 @node GNU Fortran Compiler Directives
3540 @section GNU Fortran Compiler Directives
3543 * ATTRIBUTES directive::
3544 * UNROLL directive::
3545 * BUILTIN directive::
3547 * VECTOR directive::
3548 * NOVECTOR directive::
3551 @node ATTRIBUTES directive
3552 @subsection ATTRIBUTES directive
3554 The Fortran standard describes how a conforming program shall
3555 behave; however, the exact implementation is not standardized. In order
3556 to allow the user to choose specific implementation details, compiler
3557 directives can be used to set attributes of variables and procedures
3558 which are not part of the standard. Whether a given attribute is
3559 supported and its exact effects depend on both the operating system and
3560 on the processor; see
3561 @ref{Top,,C Extensions,gcc,Using the GNU Compiler Collection (GCC)}
3564 For procedures and procedure pointers, the following attributes can
3565 be used to change the calling convention:
3568 @item @code{CDECL} -- standard C calling convention
3569 @item @code{STDCALL} -- convention where the called procedure pops the stack
3570 @item @code{FASTCALL} -- part of the arguments are passed via registers
3571 instead using the stack
3574 Besides changing the calling convention, the attributes also influence
3575 the decoration of the symbol name, e.g., by a leading underscore or by
3576 a trailing at-sign followed by the number of bytes on the stack. When
3577 assigning a procedure to a procedure pointer, both should use the same
3580 On some systems, procedures and global variables (module variables and
3581 @code{COMMON} blocks) need special handling to be accessible when they
3582 are in a shared library. The following attributes are available:
3585 @item @code{DLLEXPORT} -- provide a global pointer to a pointer in the DLL
3586 @item @code{DLLIMPORT} -- reference the function or variable using a
3590 For dummy arguments, the @code{NO_ARG_CHECK} attribute can be used; in
3591 other compilers, it is also known as @code{IGNORE_TKR}. For dummy arguments
3592 with this attribute actual arguments of any type and kind (similar to
3593 @code{TYPE(*)}), scalars and arrays of any rank (no equivalent
3594 in Fortran standard) are accepted. As with @code{TYPE(*)}, the argument
3595 is unlimited polymorphic and no type information is available.
3596 Additionally, the argument may only be passed to dummy arguments
3597 with the @code{NO_ARG_CHECK} attribute and as argument to the
3598 @code{PRESENT} intrinsic function and to @code{C_LOC} of the
3599 @code{ISO_C_BINDING} module.
3601 Variables with @code{NO_ARG_CHECK} attribute shall be of assumed-type
3602 (@code{TYPE(*)}; recommended) or of type @code{INTEGER}, @code{LOGICAL},
3603 @code{REAL} or @code{COMPLEX}. They shall not have the @code{ALLOCATE},
3604 @code{CODIMENSION}, @code{INTENT(OUT)}, @code{POINTER} or @code{VALUE}
3605 attribute; furthermore, they shall be either scalar or of assumed-size
3606 (@code{dimension(*)}). As @code{TYPE(*)}, the @code{NO_ARG_CHECK} attribute
3607 requires an explicit interface.
3610 @item @code{NO_ARG_CHECK} -- disable the type, kind and rank checking
3614 The attributes are specified using the syntax
3616 @code{!GCC$ ATTRIBUTES} @var{attribute-list} @code{::} @var{variable-list}
3618 where in free-form source code only whitespace is allowed before @code{!GCC$}
3619 and in fixed-form source code @code{!GCC$}, @code{cGCC$} or @code{*GCC$} shall
3620 start in the first column.
3622 For procedures, the compiler directives shall be placed into the body
3623 of the procedure; for variables and procedure pointers, they shall be in
3624 the same declaration part as the variable or procedure pointer.
3627 @node UNROLL directive
3628 @subsection UNROLL directive
3630 The syntax of the directive is
3632 @code{!GCC$ unroll N}
3634 You can use this directive to control how many times a loop should be unrolled.
3635 It must be placed immediately before a @code{DO} loop and applies only to the
3636 loop that follows. N is an integer constant specifying the unrolling factor.
3637 The values of 0 and 1 block any unrolling of the loop.
3640 @node BUILTIN directive
3641 @subsection BUILTIN directive
3643 The syntax of the directive is
3645 @code{!GCC$ BUILTIN (B) attributes simd FLAGS IF('target')}
3647 You can use this directive to define which middle-end built-ins provide vector
3648 implementations. @code{B} is name of the middle-end built-in. @code{FLAGS}
3649 are optional and must be either "(inbranch)" or "(notinbranch)".
3650 @code{IF} statement is optional and is used to filter multilib ABIs
3651 for the built-in that should be vectorized. Example usage:
3654 !GCC$ builtin (sinf) attributes simd (notinbranch) if('x86_64')
3657 The purpose of the directive is to provide an API among the GCC compiler and
3658 the GNU C Library which would define vector implementations of math routines.
3661 @node IVDEP directive
3662 @subsection IVDEP directive
3664 The syntax of the directive is
3668 This directive tells the compiler to ignore vector dependencies in the
3669 following loop. It must be placed immediately before a @code{DO} loop
3670 and applies only to the loop that follows.
3672 Sometimes the compiler may not have sufficient information to decide
3673 whether a particular loop is vectorizable due to potential
3674 dependencies between iterations. The purpose of the directive is to
3675 tell the compiler that vectorization is safe.
3677 This directive is intended for annotation of existing code. For new
3678 code it is recommended to consider OpenMP SIMD directives as potential
3682 @node VECTOR directive
3683 @subsection VECTOR directive
3685 The syntax of the directive is
3689 This directive tells the compiler to vectorize the following loop. It
3690 must be placed immediately before a @code{DO} loop and applies only to
3691 the loop that follows.
3694 @node NOVECTOR directive
3695 @subsection NOVECTOR directive
3697 The syntax of the directive is
3699 @code{!GCC$ novector}
3701 This directive tells the compiler to not vectorize the following loop.
3702 It must be placed immediately before a @code{DO} loop and applies only
3703 to the loop that follows.
3706 @node Non-Fortran Main Program
3707 @section Non-Fortran Main Program
3710 * _gfortran_set_args:: Save command-line arguments
3711 * _gfortran_set_options:: Set library option flags
3712 * _gfortran_set_convert:: Set endian conversion
3713 * _gfortran_set_record_marker:: Set length of record markers
3714 * _gfortran_set_fpe:: Set when a Floating Point Exception should be raised
3715 * _gfortran_set_max_subrecord_length:: Set subrecord length
3718 Even if you are doing mixed-language programming, it is very
3719 likely that you do not need to know or use the information in this
3720 section. Since it is about the internal structure of GNU Fortran,
3721 it may also change in GCC minor releases.
3723 When you compile a @code{PROGRAM} with GNU Fortran, a function
3724 with the name @code{main} (in the symbol table of the object file)
3725 is generated, which initializes the libgfortran library and then
3726 calls the actual program which uses the name @code{MAIN__}, for
3727 historic reasons. If you link GNU Fortran compiled procedures
3728 to, e.g., a C or C++ program or to a Fortran program compiled by
3729 a different compiler, the libgfortran library is not initialized
3730 and thus a few intrinsic procedures do not work properly, e.g.
3731 those for obtaining the command-line arguments.
3733 Therefore, if your @code{PROGRAM} is not compiled with
3734 GNU Fortran and the GNU Fortran compiled procedures require
3735 intrinsics relying on the library initialization, you need to
3736 initialize the library yourself. Using the default options,
3737 gfortran calls @code{_gfortran_set_args} and
3738 @code{_gfortran_set_options}. The initialization of the former
3739 is needed if the called procedures access the command line
3740 (and for backtracing); the latter sets some flags based on the
3741 standard chosen or to enable backtracing. In typical programs,
3742 it is not necessary to call any initialization function.
3744 If your @code{PROGRAM} is compiled with GNU Fortran, you shall
3745 not call any of the following functions. The libgfortran
3746 initialization functions are shown in C syntax but using C
3747 bindings they are also accessible from Fortran.
3750 @node _gfortran_set_args
3751 @subsection @code{_gfortran_set_args} --- Save command-line arguments
3752 @fnindex _gfortran_set_args
3753 @cindex libgfortran initialization, set_args
3756 @item @emph{Description}:
3757 @code{_gfortran_set_args} saves the command-line arguments; this
3758 initialization is required if any of the command-line intrinsics
3759 is called. Additionally, it shall be called if backtracing is
3760 enabled (see @code{_gfortran_set_options}).
3762 @item @emph{Syntax}:
3763 @code{void _gfortran_set_args (int argc, char *argv[])}
3765 @item @emph{Arguments}:
3766 @multitable @columnfractions .15 .70
3767 @item @var{argc} @tab number of command line argument strings
3768 @item @var{argv} @tab the command-line argument strings; argv[0]
3769 is the pathname of the executable itself.
3772 @item @emph{Example}:
3774 int main (int argc, char *argv[])
3776 /* Initialize libgfortran. */
3777 _gfortran_set_args (argc, argv);
3784 @node _gfortran_set_options
3785 @subsection @code{_gfortran_set_options} --- Set library option flags
3786 @fnindex _gfortran_set_options
3787 @cindex libgfortran initialization, set_options
3790 @item @emph{Description}:
3791 @code{_gfortran_set_options} sets several flags related to the Fortran
3792 standard to be used, whether backtracing should be enabled
3793 and whether range checks should be performed. The syntax allows for
3794 upward compatibility since the number of passed flags is specified; for
3795 non-passed flags, the default value is used. See also
3796 @pxref{Code Gen Options}. Please note that not all flags are actually
3799 @item @emph{Syntax}:
3800 @code{void _gfortran_set_options (int num, int options[])}
3802 @item @emph{Arguments}:
3803 @multitable @columnfractions .15 .70
3804 @item @var{num} @tab number of options passed
3805 @item @var{argv} @tab The list of flag values
3808 @item @emph{option flag list}:
3809 @multitable @columnfractions .15 .70
3810 @item @var{option}[0] @tab Allowed standard; can give run-time errors
3811 if e.g. an input-output edit descriptor is invalid in a given
3812 standard. Possible values are (bitwise or-ed) @code{GFC_STD_F77} (1),
3813 @code{GFC_STD_F95_OBS} (2), @code{GFC_STD_F95_DEL} (4),
3814 @code{GFC_STD_F95} (8), @code{GFC_STD_F2003} (16), @code{GFC_STD_GNU}
3815 (32), @code{GFC_STD_LEGACY} (64), @code{GFC_STD_F2008} (128),
3816 @code{GFC_STD_F2008_OBS} (256), @code{GFC_STD_F2008_TS} (512),
3817 @code{GFC_STD_F2018} (1024), @code{GFC_STD_F2018_OBS} (2048), and
3818 @code{GFC_STD=F2018_DEL} (4096). Default: @code{GFC_STD_F95_OBS |
3819 GFC_STD_F95_DEL | GFC_STD_F95 | GFC_STD_F2003 | GFC_STD_F2008 |
3820 GFC_STD_F2008_TS | GFC_STD_F2008_OBS | GFC_STD_F77 | GFC_STD_F2018 |
3821 GFC_STD_F2018_OBS | GFC_STD_F2018_DEL | GFC_STD_GNU | GFC_STD_LEGACY}.
3822 @item @var{option}[1] @tab Standard-warning flag; prints a warning to
3823 standard error. Default: @code{GFC_STD_F95_DEL | GFC_STD_LEGACY}.
3824 @item @var{option}[2] @tab If non zero, enable pedantic checking.
3826 @item @var{option}[3] @tab Unused.
3827 @item @var{option}[4] @tab If non zero, enable backtracing on run-time
3828 errors. Default: off. (Default in the compiler: on.)
3829 Note: Installs a signal handler and requires command-line
3830 initialization using @code{_gfortran_set_args}.
3831 @item @var{option}[5] @tab If non zero, supports signed zeros.
3833 @item @var{option}[6] @tab Enables run-time checking. Possible values
3834 are (bitwise or-ed): GFC_RTCHECK_BOUNDS (1), GFC_RTCHECK_ARRAY_TEMPS (2),
3835 GFC_RTCHECK_RECURSION (4), GFC_RTCHECK_DO (16), GFC_RTCHECK_POINTER (32),
3836 GFC_RTCHECK_BITS (64).
3838 @item @var{option}[7] @tab Unused.
3839 @item @var{option}[8] @tab Show a warning when invoking @code{STOP} and
3840 @code{ERROR STOP} if a floating-point exception occurred. Possible values
3841 are (bitwise or-ed) @code{GFC_FPE_INVALID} (1), @code{GFC_FPE_DENORMAL} (2),
3842 @code{GFC_FPE_ZERO} (4), @code{GFC_FPE_OVERFLOW} (8),
3843 @code{GFC_FPE_UNDERFLOW} (16), @code{GFC_FPE_INEXACT} (32). Default: None (0).
3844 (Default in the compiler: @code{GFC_FPE_INVALID | GFC_FPE_DENORMAL |
3845 GFC_FPE_ZERO | GFC_FPE_OVERFLOW | GFC_FPE_UNDERFLOW}.)
3848 @item @emph{Example}:
3850 /* Use gfortran 4.9 default options. */
3851 static int options[] = @{68, 511, 0, 0, 1, 1, 0, 0, 31@};
3852 _gfortran_set_options (9, &options);
3857 @node _gfortran_set_convert
3858 @subsection @code{_gfortran_set_convert} --- Set endian conversion
3859 @fnindex _gfortran_set_convert
3860 @cindex libgfortran initialization, set_convert
3863 @item @emph{Description}:
3864 @code{_gfortran_set_convert} set the representation of data for
3867 @item @emph{Syntax}:
3868 @code{void _gfortran_set_convert (int conv)}
3870 @item @emph{Arguments}:
3871 @multitable @columnfractions .15 .70
3872 @item @var{conv} @tab Endian conversion, possible values:
3873 GFC_CONVERT_NATIVE (0, default), GFC_CONVERT_SWAP (1),
3874 GFC_CONVERT_BIG (2), GFC_CONVERT_LITTLE (3).
3877 @item @emph{Example}:
3879 int main (int argc, char *argv[])
3881 /* Initialize libgfortran. */
3882 _gfortran_set_args (argc, argv);
3883 _gfortran_set_convert (1);
3890 @node _gfortran_set_record_marker
3891 @subsection @code{_gfortran_set_record_marker} --- Set length of record markers
3892 @fnindex _gfortran_set_record_marker
3893 @cindex libgfortran initialization, set_record_marker
3896 @item @emph{Description}:
3897 @code{_gfortran_set_record_marker} sets the length of record markers
3898 for unformatted files.
3900 @item @emph{Syntax}:
3901 @code{void _gfortran_set_record_marker (int val)}
3903 @item @emph{Arguments}:
3904 @multitable @columnfractions .15 .70
3905 @item @var{val} @tab Length of the record marker; valid values
3906 are 4 and 8. Default is 4.
3909 @item @emph{Example}:
3911 int main (int argc, char *argv[])
3913 /* Initialize libgfortran. */
3914 _gfortran_set_args (argc, argv);
3915 _gfortran_set_record_marker (8);
3922 @node _gfortran_set_fpe
3923 @subsection @code{_gfortran_set_fpe} --- Enable floating point exception traps
3924 @fnindex _gfortran_set_fpe
3925 @cindex libgfortran initialization, set_fpe
3928 @item @emph{Description}:
3929 @code{_gfortran_set_fpe} enables floating point exception traps for
3930 the specified exceptions. On most systems, this will result in a
3931 SIGFPE signal being sent and the program being aborted.
3933 @item @emph{Syntax}:
3934 @code{void _gfortran_set_fpe (int val)}
3936 @item @emph{Arguments}:
3937 @multitable @columnfractions .15 .70
3938 @item @var{option}[0] @tab IEEE exceptions. Possible values are
3939 (bitwise or-ed) zero (0, default) no trapping,
3940 @code{GFC_FPE_INVALID} (1), @code{GFC_FPE_DENORMAL} (2),
3941 @code{GFC_FPE_ZERO} (4), @code{GFC_FPE_OVERFLOW} (8),
3942 @code{GFC_FPE_UNDERFLOW} (16), and @code{GFC_FPE_INEXACT} (32).
3945 @item @emph{Example}:
3947 int main (int argc, char *argv[])
3949 /* Initialize libgfortran. */
3950 _gfortran_set_args (argc, argv);
3951 /* FPE for invalid operations such as SQRT(-1.0). */
3952 _gfortran_set_fpe (1);
3959 @node _gfortran_set_max_subrecord_length
3960 @subsection @code{_gfortran_set_max_subrecord_length} --- Set subrecord length
3961 @fnindex _gfortran_set_max_subrecord_length
3962 @cindex libgfortran initialization, set_max_subrecord_length
3965 @item @emph{Description}:
3966 @code{_gfortran_set_max_subrecord_length} set the maximum length
3967 for a subrecord. This option only makes sense for testing and
3968 debugging of unformatted I/O.
3970 @item @emph{Syntax}:
3971 @code{void _gfortran_set_max_subrecord_length (int val)}
3973 @item @emph{Arguments}:
3974 @multitable @columnfractions .15 .70
3975 @item @var{val} @tab the maximum length for a subrecord;
3976 the maximum permitted value is 2147483639, which is also
3980 @item @emph{Example}:
3982 int main (int argc, char *argv[])
3984 /* Initialize libgfortran. */
3985 _gfortran_set_args (argc, argv);
3986 _gfortran_set_max_subrecord_length (8);
3993 @node Naming and argument-passing conventions
3994 @section Naming and argument-passing conventions
3996 This section gives an overview about the naming convention of procedures
3997 and global variables and about the argument passing conventions used by
3998 GNU Fortran. If a C binding has been specified, the naming convention
3999 and some of the argument-passing conventions change. If possible,
4000 mixed-language and mixed-compiler projects should use the better defined
4001 C binding for interoperability. See @pxref{Interoperability with C}.
4004 * Naming conventions::
4005 * Argument passing conventions::
4009 @node Naming conventions
4010 @subsection Naming conventions
4012 According the Fortran standard, valid Fortran names consist of a letter
4013 between @code{A} to @code{Z}, @code{a} to @code{z}, digits @code{0},
4014 @code{1} to @code{9} and underscores (@code{_}) with the restriction
4015 that names may only start with a letter. As vendor extension, the
4016 dollar sign (@code{$}) is additionally permitted with the option
4017 @option{-fdollar-ok}, but not as first character and only if the
4018 target system supports it.
4020 By default, the procedure name is the lower-cased Fortran name with an
4021 appended underscore (@code{_}); using @option{-fno-underscoring} no
4022 underscore is appended while @code{-fsecond-underscore} appends two
4023 underscores. Depending on the target system and the calling convention,
4024 the procedure might be additionally dressed; for instance, on 32bit
4025 Windows with @code{stdcall}, an at-sign @code{@@} followed by an integer
4026 number is appended. For the changing the calling convention, see
4027 @pxref{GNU Fortran Compiler Directives}.
4029 For common blocks, the same convention is used, i.e. by default an
4030 underscore is appended to the lower-cased Fortran name. Blank commons
4031 have the name @code{__BLNK__}.
4033 For procedures and variables declared in the specification space of a
4034 module, the name is formed by @code{__}, followed by the lower-cased
4035 module name, @code{_MOD_}, and the lower-cased Fortran name. Note that
4036 no underscore is appended.
4039 @node Argument passing conventions
4040 @subsection Argument passing conventions
4042 Subroutines do not return a value (matching C99's @code{void}) while
4043 functions either return a value as specified in the platform ABI or
4044 the result variable is passed as hidden argument to the function and
4045 no result is returned. A hidden result variable is used when the
4046 result variable is an array or of type @code{CHARACTER}.
4048 Arguments are passed according to the platform ABI. In particular,
4049 complex arguments might not be compatible to a struct with two real
4050 components for the real and imaginary part. The argument passing
4051 matches the one of C99's @code{_Complex}. Functions with scalar
4052 complex result variables return their value and do not use a
4053 by-reference argument. Note that with the @option{-ff2c} option,
4054 the argument passing is modified and no longer completely matches
4055 the platform ABI. Some other Fortran compilers use @code{f2c}
4056 semantic by default; this might cause problems with
4059 GNU Fortran passes most arguments by reference, i.e. by passing a
4060 pointer to the data. Note that the compiler might use a temporary
4061 variable into which the actual argument has been copied, if required
4062 semantically (copy-in/copy-out).
4064 For arguments with @code{ALLOCATABLE} and @code{POINTER}
4065 attribute (including procedure pointers), a pointer to the pointer
4066 is passed such that the pointer address can be modified in the
4069 For dummy arguments with the @code{VALUE} attribute: Scalar arguments
4070 of the type @code{INTEGER}, @code{LOGICAL}, @code{REAL} and
4071 @code{COMPLEX} are passed by value according to the platform ABI.
4072 (As vendor extension and not recommended, using @code{%VAL()} in the
4073 call to a procedure has the same effect.) For @code{TYPE(C_PTR)} and
4074 procedure pointers, the pointer itself is passed such that it can be
4075 modified without affecting the caller.
4076 @c FIXME: Document how VALUE is handled for CHARACTER, TYPE,
4077 @c CLASS and arrays, i.e. whether the copy-in is done in the caller
4078 @c or in the callee.
4080 For Boolean (@code{LOGICAL}) arguments, please note that GCC expects
4081 only the integer value 0 and 1. If a GNU Fortran @code{LOGICAL}
4082 variable contains another integer value, the result is undefined.
4083 As some other Fortran compilers use @math{-1} for @code{.TRUE.},
4084 extra care has to be taken -- such as passing the value as
4085 @code{INTEGER}. (The same value restriction also applies to other
4086 front ends of GCC, e.g. to GCC's C99 compiler for @code{_Bool}
4087 or GCC's Ada compiler for @code{Boolean}.)
4089 For arguments of @code{CHARACTER} type, the character length is passed
4090 as a hidden argument at the end of the argument list. For
4091 deferred-length strings, the value is passed by reference, otherwise
4092 by value. The character length has the C type @code{size_t} (or
4093 @code{INTEGER(kind=C_SIZE_T)} in Fortran). Note that this is
4094 different to older versions of the GNU Fortran compiler, where the
4095 type of the hidden character length argument was a C @code{int}. In
4096 order to retain compatibility with older versions, one can e.g. for
4097 the following Fortran procedure
4100 subroutine fstrlen (s, a)
4101 character(len=*) :: s
4104 end subroutine fstrlen
4107 define the corresponding C prototype as follows:
4111 typedef size_t fortran_charlen_t;
4113 typedef int fortran_charlen_t;
4116 void fstrlen_ (char*, int*, fortran_charlen_t);
4119 In order to avoid such compiler-specific details, for new code it is
4120 instead recommended to use the ISO_C_BINDING feature.
4122 Note with C binding, @code{CHARACTER(len=1)} result variables are
4123 returned according to the platform ABI and no hidden length argument
4124 is used for dummy arguments; with @code{VALUE}, those variables are
4127 For @code{OPTIONAL} dummy arguments, an absent argument is denoted
4128 by a NULL pointer, except for scalar dummy arguments of type
4129 @code{INTEGER}, @code{LOGICAL}, @code{REAL} and @code{COMPLEX}
4130 which have the @code{VALUE} attribute. For those, a hidden Boolean
4131 argument (@code{logical(kind=C_bool),value}) is used to indicate
4132 whether the argument is present.
4134 Arguments which are assumed-shape, assumed-rank or deferred-rank
4135 arrays or, with @option{-fcoarray=lib}, allocatable scalar coarrays use
4136 an array descriptor. All other arrays pass the address of the
4137 first element of the array. With @option{-fcoarray=lib}, the token
4138 and the offset belonging to nonallocatable coarrays dummy arguments
4139 are passed as hidden argument along the character length hidden
4140 arguments. The token is an oparque pointer identifying the coarray
4141 and the offset is a passed-by-value integer of kind @code{C_PTRDIFF_T},
4142 denoting the byte offset between the base address of the coarray and
4143 the passed scalar or first element of the passed array.
4145 The arguments are passed in the following order
4147 @item Result variable, when the function result is passed by reference
4148 @item Character length of the function result, if it is a of type
4149 @code{CHARACTER} and no C binding is used
4150 @item The arguments in the order in which they appear in the Fortran
4152 @item The the present status for optional arguments with value attribute,
4153 which are internally passed by value
4154 @item The character length and/or coarray token and offset for the first
4155 argument which is a @code{CHARACTER} or a nonallocatable coarray dummy
4156 argument, followed by the hidden arguments of the next dummy argument
4161 @c ---------------------------------------------------------------------
4162 @c Coarray Programming
4163 @c ---------------------------------------------------------------------
4165 @node Coarray Programming
4166 @chapter Coarray Programming
4170 * Type and enum ABI Documentation::
4171 * Function ABI Documentation::
4175 @node Type and enum ABI Documentation
4176 @section Type and enum ABI Documentation
4181 * caf_deregister_t::
4187 @subsection @code{caf_token_t}
4189 Typedef of type @code{void *} on the compiler side. Can be any data
4190 type on the library side.
4192 @node caf_register_t
4193 @subsection @code{caf_register_t}
4195 Indicates which kind of coarray variable should be registered.
4198 typedef enum caf_register_t {
4199 CAF_REGTYPE_COARRAY_STATIC,
4200 CAF_REGTYPE_COARRAY_ALLOC,
4201 CAF_REGTYPE_LOCK_STATIC,
4202 CAF_REGTYPE_LOCK_ALLOC,
4203 CAF_REGTYPE_CRITICAL,
4204 CAF_REGTYPE_EVENT_STATIC,
4205 CAF_REGTYPE_EVENT_ALLOC,
4206 CAF_REGTYPE_COARRAY_ALLOC_REGISTER_ONLY,
4207 CAF_REGTYPE_COARRAY_ALLOC_ALLOCATE_ONLY
4212 The values @code{CAF_REGTYPE_COARRAY_ALLOC_REGISTER_ONLY} and
4213 @code{CAF_REGTYPE_COARRAY_ALLOC_ALLOCATE_ONLY} are for allocatable components
4214 in derived type coarrays only. The first one sets up the token without
4215 allocating memory for allocatable component. The latter one only allocates the
4216 memory for an allocatable component in a derived type coarray. The token
4217 needs to be setup previously by the REGISTER_ONLY. This allows to have
4218 allocatable components un-allocated on some images. The status whether an
4219 allocatable component is allocated on a remote image can be queried by
4220 @code{_caf_is_present} which used internally by the @code{ALLOCATED}
4223 @node caf_deregister_t
4224 @subsection @code{caf_deregister_t}
4227 typedef enum caf_deregister_t {
4228 CAF_DEREGTYPE_COARRAY_DEREGISTER,
4229 CAF_DEREGTYPE_COARRAY_DEALLOCATE_ONLY
4234 Allows to specifiy the type of deregistration of a coarray object. The
4235 @code{CAF_DEREGTYPE_COARRAY_DEALLOCATE_ONLY} flag is only allowed for
4236 allocatable components in derived type coarrays.
4238 @node caf_reference_t
4239 @subsection @code{caf_reference_t}
4241 The structure used for implementing arbitrary reference chains.
4242 A @code{CAF_REFERENCE_T} allows to specify a component reference or any kind
4243 of array reference of any rank supported by gfortran. For array references all
4244 kinds as known by the compiler/Fortran standard are supported indicated by
4248 typedef enum caf_ref_type_t {
4249 /* Reference a component of a derived type, either regular one or an
4250 allocatable or pointer type. For regular ones idx in caf_reference_t is
4253 /* Reference an allocatable array. */
4255 /* Reference a non-allocatable/non-pointer array. I.e., the coarray object
4256 has no array descriptor associated and the addressing is done
4257 completely using the ref. */
4258 CAF_REF_STATIC_ARRAY
4263 typedef enum caf_array_ref_t {
4264 /* No array ref. This terminates the array ref. */
4265 CAF_ARR_REF_NONE = 0,
4266 /* Reference array elements given by a vector. Only for this mode
4267 caf_reference_t.u.a.dim[i].v is valid. */
4269 /* A full array ref (:). */
4271 /* Reference a range on elements given by start, end and stride. */
4273 /* Only a single item is referenced given in the start member. */
4275 /* An array ref of the kind (i:), where i is an arbitrary valid index in the
4276 array. The index i is given in the start member. */
4277 CAF_ARR_REF_OPEN_END,
4278 /* An array ref of the kind (:i), where the lower bound of the array ref
4279 is given by the remote side. The index i is given in the end member. */
4280 CAF_ARR_REF_OPEN_START
4285 /* References to remote components of a derived type. */
4286 typedef struct caf_reference_t {
4287 /* A pointer to the next ref or NULL. */
4288 struct caf_reference_t *next;
4289 /* The type of the reference. */
4290 /* caf_ref_type_t, replaced by int to allow specification in fortran FE. */
4292 /* The size of an item referenced in bytes. I.e. in an array ref this is
4293 the factor to advance the array pointer with to get to the next item.
4294 For component refs this gives just the size of the element referenced. */
4298 /* The offset (in bytes) of the component in the derived type.
4299 Unused for allocatable or pointer components. */
4301 /* The offset (in bytes) to the caf_token associated with this
4302 component. NULL, when not allocatable/pointer ref. */
4303 ptrdiff_t caf_token_offset;
4306 /* The mode of the array ref. See CAF_ARR_REF_*. */
4307 /* caf_array_ref_t, replaced by unsigend char to allow specification in
4309 unsigned char mode[GFC_MAX_DIMENSIONS];
4310 /* The type of a static array. Unset for array's with descriptors. */
4311 int static_array_type;
4312 /* Subscript refs (s) or vector refs (v). */
4315 /* The start and end boundary of the ref and the stride. */
4316 index_type start, end, stride;
4319 /* nvec entries of kind giving the elements to reference. */
4321 /* The number of entries in vector. */
4323 /* The integer kind used for the elements in vector. */
4326 } dim[GFC_MAX_DIMENSIONS];
4332 The references make up a single linked list of reference operations. The
4333 @code{NEXT} member links to the next reference or NULL to indicate the end of
4334 the chain. Component and array refs can be arbitrarly mixed as long as they
4335 comply to the Fortran standard.
4338 The member @code{STATIC_ARRAY_TYPE} is used only when the @code{TYPE} is
4339 @code{CAF_REF_STATIC_ARRAY}. The member gives the type of the data referenced.
4340 Because no array descriptor is available for a descriptor-less array and
4341 type conversion still needs to take place the type is transported here.
4343 At the moment @code{CAF_ARR_REF_VECTOR} is not implemented in the front end for
4344 descriptor-less arrays. The library caf_single has untested support for it.
4347 @subsection @code{caf_team_t}
4349 Opaque pointer to represent a team-handle. This type is a stand-in for the
4350 future implementation of teams. It is about to change without further notice.
4352 @node Function ABI Documentation
4353 @section Function ABI Documentation
4356 * _gfortran_caf_init:: Initialiation function
4357 * _gfortran_caf_finish:: Finalization function
4358 * _gfortran_caf_this_image:: Querying the image number
4359 * _gfortran_caf_num_images:: Querying the maximal number of images
4360 * _gfortran_caf_image_status :: Query the status of an image
4361 * _gfortran_caf_failed_images :: Get an array of the indexes of the failed images
4362 * _gfortran_caf_stopped_images :: Get an array of the indexes of the stopped images
4363 * _gfortran_caf_register:: Registering coarrays
4364 * _gfortran_caf_deregister:: Deregistering coarrays
4365 * _gfortran_caf_is_present:: Query whether an allocatable or pointer component in a derived type coarray is allocated
4366 * _gfortran_caf_send:: Sending data from a local image to a remote image
4367 * _gfortran_caf_get:: Getting data from a remote image
4368 * _gfortran_caf_sendget:: Sending data between remote images
4369 * _gfortran_caf_send_by_ref:: Sending data from a local image to a remote image using enhanced references
4370 * _gfortran_caf_get_by_ref:: Getting data from a remote image using enhanced references
4371 * _gfortran_caf_sendget_by_ref:: Sending data between remote images using enhanced references
4372 * _gfortran_caf_lock:: Locking a lock variable
4373 * _gfortran_caf_unlock:: Unlocking a lock variable
4374 * _gfortran_caf_event_post:: Post an event
4375 * _gfortran_caf_event_wait:: Wait that an event occurred
4376 * _gfortran_caf_event_query:: Query event count
4377 * _gfortran_caf_sync_all:: All-image barrier
4378 * _gfortran_caf_sync_images:: Barrier for selected images
4379 * _gfortran_caf_sync_memory:: Wait for completion of segment-memory operations
4380 * _gfortran_caf_error_stop:: Error termination with exit code
4381 * _gfortran_caf_error_stop_str:: Error termination with string
4382 * _gfortran_caf_fail_image :: Mark the image failed and end its execution
4383 * _gfortran_caf_atomic_define:: Atomic variable assignment
4384 * _gfortran_caf_atomic_ref:: Atomic variable reference
4385 * _gfortran_caf_atomic_cas:: Atomic compare and swap
4386 * _gfortran_caf_atomic_op:: Atomic operation
4387 * _gfortran_caf_co_broadcast:: Sending data to all images
4388 * _gfortran_caf_co_max:: Collective maximum reduction
4389 * _gfortran_caf_co_min:: Collective minimum reduction
4390 * _gfortran_caf_co_sum:: Collective summing reduction
4391 * _gfortran_caf_co_reduce:: Generic collective reduction
4395 @node _gfortran_caf_init
4396 @subsection @code{_gfortran_caf_init} --- Initialiation function
4397 @cindex Coarray, _gfortran_caf_init
4400 @item @emph{Description}:
4401 This function is called at startup of the program before the Fortran main
4402 program, if the latter has been compiled with @option{-fcoarray=lib}.
4403 It takes as arguments the command-line arguments of the program. It is
4404 permitted to pass two @code{NULL} pointers as argument; if non-@code{NULL},
4405 the library is permitted to modify the arguments.
4407 @item @emph{Syntax}:
4408 @code{void _gfortran_caf_init (int *argc, char ***argv)}
4410 @item @emph{Arguments}:
4411 @multitable @columnfractions .15 .70
4412 @item @var{argc} @tab intent(inout) An integer pointer with the number of
4413 arguments passed to the program or @code{NULL}.
4414 @item @var{argv} @tab intent(inout) A pointer to an array of strings with the
4415 command-line arguments or @code{NULL}.
4419 The function is modelled after the initialization function of the Message
4420 Passing Interface (MPI) specification. Due to the way coarray registration
4421 works, it might not be the first call to the library. If the main program is
4422 not written in Fortran and only a library uses coarrays, it can happen that
4423 this function is never called. Therefore, it is recommended that the library
4424 does not rely on the passed arguments and whether the call has been done.
4428 @node _gfortran_caf_finish
4429 @subsection @code{_gfortran_caf_finish} --- Finalization function
4430 @cindex Coarray, _gfortran_caf_finish
4433 @item @emph{Description}:
4434 This function is called at the end of the Fortran main program, if it has
4435 been compiled with the @option{-fcoarray=lib} option.
4437 @item @emph{Syntax}:
4438 @code{void _gfortran_caf_finish (void)}
4441 For non-Fortran programs, it is recommended to call the function at the end
4442 of the main program. To ensure that the shutdown is also performed for
4443 programs where this function is not explicitly invoked, for instance
4444 non-Fortran programs or calls to the system's exit() function, the library
4445 can use a destructor function. Note that programs can also be terminated
4446 using the STOP and ERROR STOP statements; those use different library calls.
4450 @node _gfortran_caf_this_image
4451 @subsection @code{_gfortran_caf_this_image} --- Querying the image number
4452 @cindex Coarray, _gfortran_caf_this_image
4455 @item @emph{Description}:
4456 This function returns the current image number, which is a positive number.
4458 @item @emph{Syntax}:
4459 @code{int _gfortran_caf_this_image (int distance)}
4461 @item @emph{Arguments}:
4462 @multitable @columnfractions .15 .70
4463 @item @var{distance} @tab As specified for the @code{this_image} intrinsic
4464 in TS18508. Shall be a non-negative number.
4468 If the Fortran intrinsic @code{this_image} is invoked without an argument, which
4469 is the only permitted form in Fortran 2008, GCC passes @code{0} as
4474 @node _gfortran_caf_num_images
4475 @subsection @code{_gfortran_caf_num_images} --- Querying the maximal number of images
4476 @cindex Coarray, _gfortran_caf_num_images
4479 @item @emph{Description}:
4480 This function returns the number of images in the current team, if
4481 @var{distance} is 0 or the number of images in the parent team at the specified
4482 distance. If failed is -1, the function returns the number of all images at
4483 the specified distance; if it is 0, the function returns the number of
4484 nonfailed images, and if it is 1, it returns the number of failed images.
4486 @item @emph{Syntax}:
4487 @code{int _gfortran_caf_num_images(int distance, int failed)}
4489 @item @emph{Arguments}:
4490 @multitable @columnfractions .15 .70
4491 @item @var{distance} @tab the distance from this image to the ancestor.
4493 @item @var{failed} @tab shall be -1, 0, or 1
4497 This function follows TS18508. If the num_image intrinsic has no arguments,
4498 then the compiler passes @code{distance=0} and @code{failed=-1} to the function.
4502 @node _gfortran_caf_image_status
4503 @subsection @code{_gfortran_caf_image_status} --- Query the status of an image
4504 @cindex Coarray, _gfortran_caf_image_status
4507 @item @emph{Description}:
4508 Get the status of the image given by the id @var{image} of the team given by
4509 @var{team}. Valid results are zero, for image is ok, @code{STAT_STOPPED_IMAGE}
4510 from the ISO_FORTRAN_ENV module to indicate that the image has been stopped and
4511 @code{STAT_FAILED_IMAGE} also from ISO_FORTRAN_ENV to indicate that the image
4512 has executed a @code{FAIL IMAGE} statement.
4514 @item @emph{Syntax}:
4515 @code{int _gfortran_caf_image_status (int image, caf_team_t * team)}
4517 @item @emph{Arguments}:
4518 @multitable @columnfractions .15 .70
4519 @item @var{image} @tab the positive scalar id of the image in the current TEAM.
4520 @item @var{team} @tab optional; team on the which the inquiry is to be
4525 This function follows TS18508. Because team-functionality is not yet
4526 implemented a null-pointer is passed for the @var{team} argument at the moment.
4530 @node _gfortran_caf_failed_images
4531 @subsection @code{_gfortran_caf_failed_images} --- Get an array of the indexes of the failed images
4532 @cindex Coarray, _gfortran_caf_failed_images
4535 @item @emph{Description}:
4536 Get an array of image indexes in the current @var{team} that have failed. The
4537 array is sorted ascendingly. When @var{team} is not provided the current team
4538 is to be used. When @var{kind} is provided then the resulting array is of that
4539 integer kind else it is of default integer kind. The returns an unallocated
4540 size zero array when no images have failed.
4542 @item @emph{Syntax}:
4543 @code{int _gfortran_caf_failed_images (caf_team_t * team, int * kind)}
4545 @item @emph{Arguments}:
4546 @multitable @columnfractions .15 .70
4547 @item @var{team} @tab optional; team on the which the inquiry is to be
4549 @item @var{image} @tab optional; the kind of the resulting integer array.
4553 This function follows TS18508. Because team-functionality is not yet
4554 implemented a null-pointer is passed for the @var{team} argument at the moment.
4558 @node _gfortran_caf_stopped_images
4559 @subsection @code{_gfortran_caf_stopped_images} --- Get an array of the indexes of the stopped images
4560 @cindex Coarray, _gfortran_caf_stopped_images
4563 @item @emph{Description}:
4564 Get an array of image indexes in the current @var{team} that have stopped. The
4565 array is sorted ascendingly. When @var{team} is not provided the current team
4566 is to be used. When @var{kind} is provided then the resulting array is of that
4567 integer kind else it is of default integer kind. The returns an unallocated
4568 size zero array when no images have failed.
4570 @item @emph{Syntax}:
4571 @code{int _gfortran_caf_stopped_images (caf_team_t * team, int * kind)}
4573 @item @emph{Arguments}:
4574 @multitable @columnfractions .15 .70
4575 @item @var{team} @tab optional; team on the which the inquiry is to be
4577 @item @var{image} @tab optional; the kind of the resulting integer array.
4581 This function follows TS18508. Because team-functionality is not yet
4582 implemented a null-pointer is passed for the @var{team} argument at the moment.
4586 @node _gfortran_caf_register
4587 @subsection @code{_gfortran_caf_register} --- Registering coarrays
4588 @cindex Coarray, _gfortran_caf_register
4591 @item @emph{Description}:
4592 Registers memory for a coarray and creates a token to identify the coarray. The
4593 routine is called for both coarrays with @code{SAVE} attribute and using an
4594 explicit @code{ALLOCATE} statement. If an error occurs and @var{STAT} is a
4595 @code{NULL} pointer, the function shall abort with printing an error message
4596 and starting the error termination. If no error occurs and @var{STAT} is
4597 present, it shall be set to zero. Otherwise, it shall be set to a positive
4598 value and, if not-@code{NULL}, @var{ERRMSG} shall be set to a string describing
4599 the failure. The routine shall register the memory provided in the
4600 @code{DATA}-component of the array descriptor @var{DESC}, when that component
4601 is non-@code{NULL}, else it shall allocate sufficient memory and provide a
4602 pointer to it in the @code{DATA}-component of @var{DESC}. The array descriptor
4603 has rank zero, when a scalar object is to be registered and the array
4604 descriptor may be invalid after the call to @code{_gfortran_caf_register}.
4605 When an array is to be allocated the descriptor persists.
4607 For @code{CAF_REGTYPE_COARRAY_STATIC} and @code{CAF_REGTYPE_COARRAY_ALLOC},
4608 the passed size is the byte size requested. For @code{CAF_REGTYPE_LOCK_STATIC},
4609 @code{CAF_REGTYPE_LOCK_ALLOC} and @code{CAF_REGTYPE_CRITICAL} it is the array
4610 size or one for a scalar.
4612 When @code{CAF_REGTYPE_COARRAY_ALLOC_REGISTER_ONLY} is used, then only a token
4613 for an allocatable or pointer component is created. The @code{SIZE} parameter
4614 is not used then. On the contrary when
4615 @code{CAF_REGTYPE_COARRAY_ALLOC_ALLOCATE_ONLY} is specified, then the
4616 @var{token} needs to be registered by a previous call with regtype
4617 @code{CAF_REGTYPE_COARRAY_ALLOC_REGISTER_ONLY} and either the memory specified
4618 in the @var{DESC}'s data-ptr is registered or allocate when the data-ptr is
4621 @item @emph{Syntax}:
4622 @code{void caf_register (size_t size, caf_register_t type, caf_token_t *token,
4623 gfc_descriptor_t *desc, int *stat, char *errmsg, size_t errmsg_len)}
4625 @item @emph{Arguments}:
4626 @multitable @columnfractions .15 .70
4627 @item @var{size} @tab For normal coarrays, the byte size of the coarray to be
4628 allocated; for lock types and event types, the number of elements.
4629 @item @var{type} @tab one of the caf_register_t types.
4630 @item @var{token} @tab intent(out) An opaque pointer identifying the coarray.
4631 @item @var{desc} @tab intent(inout) The (pseudo) array descriptor.
4632 @item @var{stat} @tab intent(out) For allocatable coarrays, stores the STAT=;
4634 @item @var{errmsg} @tab intent(out) When an error occurs, this will be set to
4635 an error message; may be @code{NULL}
4636 @item @var{errmsg_len} @tab the buffer size of errmsg.
4640 Nonallocatable coarrays have to be registered prior use from remote images.
4641 In order to guarantee this, they have to be registered before the main
4642 program. This can be achieved by creating constructor functions. That is what
4643 GCC does such that also for nonallocatable coarrays the memory is allocated and
4644 no static memory is used. The token permits to identify the coarray; to the
4645 processor, the token is a nonaliasing pointer. The library can, for instance,
4646 store the base address of the coarray in the token, some handle or a more
4647 complicated struct. The library may also store the array descriptor
4648 @var{DESC} when its rank is non-zero.
4650 For lock types, the value shall only be used for checking the allocation
4651 status. Note that for critical blocks, the locking is only required on one
4652 image; in the locking statement, the processor shall always pass an
4653 image index of one for critical-block lock variables
4654 (@code{CAF_REGTYPE_CRITICAL}). For lock types and critical-block variables,
4655 the initial value shall be unlocked (or, respecitively, not in critical
4656 section) such as the value false; for event types, the initial state should
4657 be no event, e.g. zero.
4661 @node _gfortran_caf_deregister
4662 @subsection @code{_gfortran_caf_deregister} --- Deregistering coarrays
4663 @cindex Coarray, _gfortran_caf_deregister
4666 @item @emph{Description}:
4667 Called to free or deregister the memory of a coarray; the processor calls this
4668 function for automatic and explicit deallocation. In case of an error, this
4669 function shall fail with an error message, unless the @var{STAT} variable is
4670 not null. The library is only expected to free memory it allocated itself
4671 during a call to @code{_gfortran_caf_register}.
4673 @item @emph{Syntax}:
4674 @code{void caf_deregister (caf_token_t *token, caf_deregister_t type,
4675 int *stat, char *errmsg, size_t errmsg_len)}
4677 @item @emph{Arguments}:
4678 @multitable @columnfractions .15 .70
4679 @item @var{token} @tab the token to free.
4680 @item @var{type} @tab the type of action to take for the coarray. A
4681 @code{CAF_DEREGTYPE_COARRAY_DEALLOCATE_ONLY} is allowed only for allocatable or
4682 pointer components of derived type coarrays. The action only deallocates the
4683 local memory without deleting the token.
4684 @item @var{stat} @tab intent(out) Stores the STAT=; may be NULL
4685 @item @var{errmsg} @tab intent(out) When an error occurs, this will be set
4686 to an error message; may be NULL
4687 @item @var{errmsg_len} @tab the buffer size of errmsg.
4691 For nonalloatable coarrays this function is never called. If a cleanup is
4692 required, it has to be handled via the finish, stop and error stop functions,
4693 and via destructors.
4697 @node _gfortran_caf_is_present
4698 @subsection @code{_gfortran_caf_is_present} --- Query whether an allocatable or pointer component in a derived type coarray is allocated
4699 @cindex Coarray, _gfortran_caf_is_present
4702 @item @emph{Description}:
4703 Used to query the coarray library whether an allocatable component in a derived
4704 type coarray is allocated on a remote image.
4706 @item @emph{Syntax}:
4707 @code{void _gfortran_caf_is_present (caf_token_t token, int image_index,
4708 gfc_reference_t *ref)}
4710 @item @emph{Arguments}:
4711 @multitable @columnfractions .15 .70
4712 @item @var{token} @tab An opaque pointer identifying the coarray.
4713 @item @var{image_index} @tab The ID of the remote image; must be a positive
4715 @item @var{ref} @tab A chain of references to address the allocatable or
4716 pointer component in the derived type coarray. The object reference needs to be
4717 a scalar or a full array reference, respectively.
4722 @node _gfortran_caf_send
4723 @subsection @code{_gfortran_caf_send} --- Sending data from a local image to a remote image
4724 @cindex Coarray, _gfortran_caf_send
4727 @item @emph{Description}:
4728 Called to send a scalar, an array section or a whole array from a local
4729 to a remote image identified by the image_index.
4731 @item @emph{Syntax}:
4732 @code{void _gfortran_caf_send (caf_token_t token, size_t offset,
4733 int image_index, gfc_descriptor_t *dest, caf_vector_t *dst_vector,
4734 gfc_descriptor_t *src, int dst_kind, int src_kind, bool may_require_tmp,
4737 @item @emph{Arguments}:
4738 @multitable @columnfractions .15 .70
4739 @item @var{token} @tab intent(in) An opaque pointer identifying the coarray.
4740 @item @var{offset} @tab intent(in) By which amount of bytes the actual data is
4741 shifted compared to the base address of the coarray.
4742 @item @var{image_index} @tab intent(in) The ID of the remote image; must be a
4744 @item @var{dest} @tab intent(in) Array descriptor for the remote image for the
4745 bounds and the size. The @code{base_addr} shall not be accessed.
4746 @item @var{dst_vector} @tab intent(in) If not NULL, it contains the vector
4747 subscript of the destination array; the values are relative to the dimension
4748 triplet of the dest argument.
4749 @item @var{src} @tab intent(in) Array descriptor of the local array to be
4750 transferred to the remote image
4751 @item @var{dst_kind} @tab intent(in) Kind of the destination argument
4752 @item @var{src_kind} @tab intent(in) Kind of the source argument
4753 @item @var{may_require_tmp} @tab intent(in) The variable is @code{false} when
4754 it is known at compile time that the @var{dest} and @var{src} either cannot
4755 overlap or overlap (fully or partially) such that walking @var{src} and
4756 @var{dest} in element wise element order (honoring the stride value) will not
4757 lead to wrong results. Otherwise, the value is @code{true}.
4758 @item @var{stat} @tab intent(out) when non-NULL give the result of the
4759 operation, i.e., zero on success and non-zero on error. When NULL and an error
4760 occurs, then an error message is printed and the program is terminated.
4764 It is permitted to have @var{image_index} equal the current image; the memory
4765 of the send-to and the send-from might (partially) overlap in that case. The
4766 implementation has to take care that it handles this case, e.g. using
4767 @code{memmove} which handles (partially) overlapping memory. If
4768 @var{may_require_tmp} is true, the library might additionally create a
4769 temporary variable, unless additional checks show that this is not required
4770 (e.g. because walking backward is possible or because both arrays are
4771 contiguous and @code{memmove} takes care of overlap issues).
4773 Note that the assignment of a scalar to an array is permitted. In addition,
4774 the library has to handle numeric-type conversion and for strings, padding
4775 and different character kinds.
4779 @node _gfortran_caf_get
4780 @subsection @code{_gfortran_caf_get} --- Getting data from a remote image
4781 @cindex Coarray, _gfortran_caf_get
4784 @item @emph{Description}:
4785 Called to get an array section or a whole array from a remote,
4786 image identified by the image_index.
4788 @item @emph{Syntax}:
4789 @code{void _gfortran_caf_get (caf_token_t token, size_t offset,
4790 int image_index, gfc_descriptor_t *src, caf_vector_t *src_vector,
4791 gfc_descriptor_t *dest, int src_kind, int dst_kind, bool may_require_tmp,
4794 @item @emph{Arguments}:
4795 @multitable @columnfractions .15 .70
4796 @item @var{token} @tab intent(in) An opaque pointer identifying the coarray.
4797 @item @var{offset} @tab intent(in) By which amount of bytes the actual data is
4798 shifted compared to the base address of the coarray.
4799 @item @var{image_index} @tab intent(in) The ID of the remote image; must be a
4801 @item @var{dest} @tab intent(out) Array descriptor of the local array to store
4802 the data retrieved from the remote image
4803 @item @var{src} @tab intent(in) Array descriptor for the remote image for the
4804 bounds and the size. The @code{base_addr} shall not be accessed.
4805 @item @var{src_vector} @tab intent(in) If not NULL, it contains the vector
4806 subscript of the source array; the values are relative to the dimension
4807 triplet of the @var{src} argument.
4808 @item @var{dst_kind} @tab intent(in) Kind of the destination argument
4809 @item @var{src_kind} @tab intent(in) Kind of the source argument
4810 @item @var{may_require_tmp} @tab intent(in) The variable is @code{false} when
4811 it is known at compile time that the @var{dest} and @var{src} either cannot
4812 overlap or overlap (fully or partially) such that walking @var{src} and
4813 @var{dest} in element wise element order (honoring the stride value) will not
4814 lead to wrong results. Otherwise, the value is @code{true}.
4815 @item @var{stat} @tab intent(out) When non-NULL give the result of the
4816 operation, i.e., zero on success and non-zero on error. When NULL and an error
4817 occurs, then an error message is printed and the program is terminated.
4821 It is permitted to have @var{image_index} equal the current image; the memory of
4822 the send-to and the send-from might (partially) overlap in that case. The
4823 implementation has to take care that it handles this case, e.g. using
4824 @code{memmove} which handles (partially) overlapping memory. If
4825 @var{may_require_tmp} is true, the library might additionally create a
4826 temporary variable, unless additional checks show that this is not required
4827 (e.g. because walking backward is possible or because both arrays are
4828 contiguous and @code{memmove} takes care of overlap issues).
4830 Note that the library has to handle numeric-type conversion and for strings,
4831 padding and different character kinds.
4835 @node _gfortran_caf_sendget
4836 @subsection @code{_gfortran_caf_sendget} --- Sending data between remote images
4837 @cindex Coarray, _gfortran_caf_sendget
4840 @item @emph{Description}:
4841 Called to send a scalar, an array section or a whole array from a remote image
4842 identified by the @var{src_image_index} to a remote image identified by the
4843 @var{dst_image_index}.
4845 @item @emph{Syntax}:
4846 @code{void _gfortran_caf_sendget (caf_token_t dst_token, size_t dst_offset,
4847 int dst_image_index, gfc_descriptor_t *dest, caf_vector_t *dst_vector,
4848 caf_token_t src_token, size_t src_offset, int src_image_index,
4849 gfc_descriptor_t *src, caf_vector_t *src_vector, int dst_kind, int src_kind,
4850 bool may_require_tmp, int *stat)}
4852 @item @emph{Arguments}:
4853 @multitable @columnfractions .15 .70
4854 @item @var{dst_token} @tab intent(in) An opaque pointer identifying the
4855 destination coarray.
4856 @item @var{dst_offset} @tab intent(in) By which amount of bytes the actual data
4857 is shifted compared to the base address of the destination coarray.
4858 @item @var{dst_image_index} @tab intent(in) The ID of the destination remote
4859 image; must be a positive number.
4860 @item @var{dest} @tab intent(in) Array descriptor for the destination
4861 remote image for the bounds and the size. The @code{base_addr} shall not be
4863 @item @var{dst_vector} @tab intent(int) If not NULL, it contains the vector
4864 subscript of the destination array; the values are relative to the dimension
4865 triplet of the @var{dest} argument.
4866 @item @var{src_token} @tab intent(in) An opaque pointer identifying the source
4868 @item @var{src_offset} @tab intent(in) By which amount of bytes the actual data
4869 is shifted compared to the base address of the source coarray.
4870 @item @var{src_image_index} @tab intent(in) The ID of the source remote image;
4871 must be a positive number.
4872 @item @var{src} @tab intent(in) Array descriptor of the local array to be
4873 transferred to the remote image.
4874 @item @var{src_vector} @tab intent(in) Array descriptor of the local array to
4875 be transferred to the remote image
4876 @item @var{dst_kind} @tab intent(in) Kind of the destination argument
4877 @item @var{src_kind} @tab intent(in) Kind of the source argument
4878 @item @var{may_require_tmp} @tab intent(in) The variable is @code{false} when
4879 it is known at compile time that the @var{dest} and @var{src} either cannot
4880 overlap or overlap (fully or partially) such that walking @var{src} and
4881 @var{dest} in element wise element order (honoring the stride value) will not
4882 lead to wrong results. Otherwise, the value is @code{true}.
4883 @item @var{stat} @tab intent(out) when non-NULL give the result of the
4884 operation, i.e., zero on success and non-zero on error. When NULL and an error
4885 occurs, then an error message is printed and the program is terminated.
4889 It is permitted to have the same image index for both @var{src_image_index} and
4890 @var{dst_image_index}; the memory of the send-to and the send-from might
4891 (partially) overlap in that case. The implementation has to take care that it
4892 handles this case, e.g. using @code{memmove} which handles (partially)
4893 overlapping memory. If @var{may_require_tmp} is true, the library
4894 might additionally create a temporary variable, unless additional checks show
4895 that this is not required (e.g. because walking backward is possible or because
4896 both arrays are contiguous and @code{memmove} takes care of overlap issues).
4898 Note that the assignment of a scalar to an array is permitted. In addition,
4899 the library has to handle numeric-type conversion and for strings, padding and
4900 different character kinds.
4903 @node _gfortran_caf_send_by_ref
4904 @subsection @code{_gfortran_caf_send_by_ref} --- Sending data from a local image to a remote image with enhanced referencing options
4905 @cindex Coarray, _gfortran_caf_send_by_ref
4908 @item @emph{Description}:
4909 Called to send a scalar, an array section or a whole array from a local to a
4910 remote image identified by the @var{image_index}.
4912 @item @emph{Syntax}:
4913 @code{void _gfortran_caf_send_by_ref (caf_token_t token, int image_index,
4914 gfc_descriptor_t *src, caf_reference_t *refs, int dst_kind, int src_kind,
4915 bool may_require_tmp, bool dst_reallocatable, int *stat, int dst_type)}
4917 @item @emph{Arguments}:
4918 @multitable @columnfractions .15 .70
4919 @item @var{token} @tab intent(in) An opaque pointer identifying the coarray.
4920 @item @var{image_index} @tab intent(in) The ID of the remote image; must be a
4922 @item @var{src} @tab intent(in) Array descriptor of the local array to be
4923 transferred to the remote image
4924 @item @var{refs} @tab intent(in) The references on the remote array to store
4925 the data given by src. Guaranteed to have at least one entry.
4926 @item @var{dst_kind} @tab intent(in) Kind of the destination argument
4927 @item @var{src_kind} @tab intent(in) Kind of the source argument
4928 @item @var{may_require_tmp} @tab intent(in) The variable is @code{false} when
4929 it is known at compile time that the @var{dest} and @var{src} either cannot
4930 overlap or overlap (fully or partially) such that walking @var{src} and
4931 @var{dest} in element wise element order (honoring the stride value) will not
4932 lead to wrong results. Otherwise, the value is @code{true}.
4933 @item @var{dst_reallocatable} @tab intent(in) Set when the destination is of
4934 allocatable or pointer type and the refs will allow reallocation, i.e., the ref
4935 is a full array or component ref.
4936 @item @var{stat} @tab intent(out) When non-@code{NULL} give the result of the
4937 operation, i.e., zero on success and non-zero on error. When @code{NULL} and
4938 an error occurs, then an error message is printed and the program is terminated.
4939 @item @var{dst_type} @tab intent(in) Give the type of the destination. When
4940 the destination is not an array, than the precise type, e.g. of a component in
4941 a derived type, is not known, but provided here.
4945 It is permitted to have @var{image_index} equal the current image; the memory of
4946 the send-to and the send-from might (partially) overlap in that case. The
4947 implementation has to take care that it handles this case, e.g. using
4948 @code{memmove} which handles (partially) overlapping memory. If
4949 @var{may_require_tmp} is true, the library might additionally create a
4950 temporary variable, unless additional checks show that this is not required
4951 (e.g. because walking backward is possible or because both arrays are
4952 contiguous and @code{memmove} takes care of overlap issues).
4954 Note that the assignment of a scalar to an array is permitted. In addition,
4955 the library has to handle numeric-type conversion and for strings, padding
4956 and different character kinds.
4958 Because of the more complicated references possible some operations may be
4959 unsupported by certain libraries. The library is expected to issue a precise
4960 error message why the operation is not permitted.
4964 @node _gfortran_caf_get_by_ref
4965 @subsection @code{_gfortran_caf_get_by_ref} --- Getting data from a remote image using enhanced references
4966 @cindex Coarray, _gfortran_caf_get_by_ref
4969 @item @emph{Description}:
4970 Called to get a scalar, an array section or a whole array from a remote image
4971 identified by the @var{image_index}.
4973 @item @emph{Syntax}:
4974 @code{void _gfortran_caf_get_by_ref (caf_token_t token, int image_index,
4975 caf_reference_t *refs, gfc_descriptor_t *dst, int dst_kind, int src_kind,
4976 bool may_require_tmp, bool dst_reallocatable, int *stat, int src_type)}
4978 @item @emph{Arguments}:
4979 @multitable @columnfractions .15 .70
4980 @item @var{token} @tab intent(in) An opaque pointer identifying the coarray.
4981 @item @var{image_index} @tab intent(in) The ID of the remote image; must be a
4983 @item @var{refs} @tab intent(in) The references to apply to the remote structure
4985 @item @var{dst} @tab intent(in) Array descriptor of the local array to store
4986 the data transferred from the remote image. May be reallocated where needed
4987 and when @var{DST_REALLOCATABLE} allows it.
4988 @item @var{dst_kind} @tab intent(in) Kind of the destination argument
4989 @item @var{src_kind} @tab intent(in) Kind of the source argument
4990 @item @var{may_require_tmp} @tab intent(in) The variable is @code{false} when
4991 it is known at compile time that the @var{dest} and @var{src} either cannot
4992 overlap or overlap (fully or partially) such that walking @var{src} and
4993 @var{dest} in element wise element order (honoring the stride value) will not
4994 lead to wrong results. Otherwise, the value is @code{true}.
4995 @item @var{dst_reallocatable} @tab intent(in) Set when @var{DST} is of
4996 allocatable or pointer type and its refs allow reallocation, i.e., the full
4997 array or a component is referenced.
4998 @item @var{stat} @tab intent(out) When non-@code{NULL} give the result of the
4999 operation, i.e., zero on success and non-zero on error. When @code{NULL} and an
5000 error occurs, then an error message is printed and the program is terminated.
5001 @item @var{src_type} @tab intent(in) Give the type of the source. When the
5002 source is not an array, than the precise type, e.g. of a component in a
5003 derived type, is not known, but provided here.
5007 It is permitted to have @code{image_index} equal the current image; the memory
5008 of the send-to and the send-from might (partially) overlap in that case. The
5009 implementation has to take care that it handles this case, e.g. using
5010 @code{memmove} which handles (partially) overlapping memory. If
5011 @var{may_require_tmp} is true, the library might additionally create a
5012 temporary variable, unless additional checks show that this is not required
5013 (e.g. because walking backward is possible or because both arrays are
5014 contiguous and @code{memmove} takes care of overlap issues).
5016 Note that the library has to handle numeric-type conversion and for strings,
5017 padding and different character kinds.
5019 Because of the more complicated references possible some operations may be
5020 unsupported by certain libraries. The library is expected to issue a precise
5021 error message why the operation is not permitted.
5025 @node _gfortran_caf_sendget_by_ref
5026 @subsection @code{_gfortran_caf_sendget_by_ref} --- Sending data between remote images using enhanced references on both sides
5027 @cindex Coarray, _gfortran_caf_sendget_by_ref
5030 @item @emph{Description}:
5031 Called to send a scalar, an array section or a whole array from a remote image
5032 identified by the @var{src_image_index} to a remote image identified by the
5033 @var{dst_image_index}.
5035 @item @emph{Syntax}:
5036 @code{void _gfortran_caf_sendget_by_ref (caf_token_t dst_token,
5037 int dst_image_index, caf_reference_t *dst_refs,
5038 caf_token_t src_token, int src_image_index, caf_reference_t *src_refs,
5039 int dst_kind, int src_kind, bool may_require_tmp, int *dst_stat,
5040 int *src_stat, int dst_type, int src_type)}
5042 @item @emph{Arguments}:
5043 @multitable @columnfractions .15 .70
5044 @item @var{dst_token} @tab intent(in) An opaque pointer identifying the
5045 destination coarray.
5046 @item @var{dst_image_index} @tab intent(in) The ID of the destination remote
5047 image; must be a positive number.
5048 @item @var{dst_refs} @tab intent(in) The references on the remote array to store
5049 the data given by the source. Guaranteed to have at least one entry.
5050 @item @var{src_token} @tab intent(in) An opaque pointer identifying the source
5052 @item @var{src_image_index} @tab intent(in) The ID of the source remote image;
5053 must be a positive number.
5054 @item @var{src_refs} @tab intent(in) The references to apply to the remote
5055 structure to get the data.
5056 @item @var{dst_kind} @tab intent(in) Kind of the destination argument
5057 @item @var{src_kind} @tab intent(in) Kind of the source argument
5058 @item @var{may_require_tmp} @tab intent(in) The variable is @code{false} when
5059 it is known at compile time that the @var{dest} and @var{src} either cannot
5060 overlap or overlap (fully or partially) such that walking @var{src} and
5061 @var{dest} in element wise element order (honoring the stride value) will not
5062 lead to wrong results. Otherwise, the value is @code{true}.
5063 @item @var{dst_stat} @tab intent(out) when non-@code{NULL} give the result of
5064 the send-operation, i.e., zero on success and non-zero on error. When
5065 @code{NULL} and an error occurs, then an error message is printed and the
5066 program is terminated.
5067 @item @var{src_stat} @tab intent(out) When non-@code{NULL} give the result of
5068 the get-operation, i.e., zero on success and non-zero on error. When
5069 @code{NULL} and an error occurs, then an error message is printed and the
5070 program is terminated.
5071 @item @var{dst_type} @tab intent(in) Give the type of the destination. When
5072 the destination is not an array, than the precise type, e.g. of a component in
5073 a derived type, is not known, but provided here.
5074 @item @var{src_type} @tab intent(in) Give the type of the source. When the
5075 source is not an array, than the precise type, e.g. of a component in a
5076 derived type, is not known, but provided here.
5080 It is permitted to have the same image index for both @var{src_image_index} and
5081 @var{dst_image_index}; the memory of the send-to and the send-from might
5082 (partially) overlap in that case. The implementation has to take care that it
5083 handles this case, e.g. using @code{memmove} which handles (partially)
5084 overlapping memory. If @var{may_require_tmp} is true, the library
5085 might additionally create a temporary variable, unless additional checks show
5086 that this is not required (e.g. because walking backward is possible or because
5087 both arrays are contiguous and @code{memmove} takes care of overlap issues).
5089 Note that the assignment of a scalar to an array is permitted. In addition,
5090 the library has to handle numeric-type conversion and for strings, padding and
5091 different character kinds.
5093 Because of the more complicated references possible some operations may be
5094 unsupported by certain libraries. The library is expected to issue a precise
5095 error message why the operation is not permitted.
5099 @node _gfortran_caf_lock
5100 @subsection @code{_gfortran_caf_lock} --- Locking a lock variable
5101 @cindex Coarray, _gfortran_caf_lock
5104 @item @emph{Description}:
5105 Acquire a lock on the given image on a scalar locking variable or for the
5106 given array element for an array-valued variable. If the @var{aquired_lock}
5107 is @code{NULL}, the function returns after having obtained the lock. If it is
5108 non-@code{NULL}, then @var{acquired_lock} is assigned the value true (one) when
5109 the lock could be obtained and false (zero) otherwise. Locking a lock variable
5110 which has already been locked by the same image is an error.
5112 @item @emph{Syntax}:
5113 @code{void _gfortran_caf_lock (caf_token_t token, size_t index, int image_index,
5114 int *aquired_lock, int *stat, char *errmsg, size_t errmsg_len)}
5116 @item @emph{Arguments}:
5117 @multitable @columnfractions .15 .70
5118 @item @var{token} @tab intent(in) An opaque pointer identifying the coarray.
5119 @item @var{index} @tab intent(in) Array index; first array index is 0. For
5120 scalars, it is always 0.
5121 @item @var{image_index} @tab intent(in) The ID of the remote image; must be a
5123 @item @var{aquired_lock} @tab intent(out) If not NULL, it returns whether lock
5125 @item @var{stat} @tab intent(out) Stores the STAT=; may be NULL.
5126 @item @var{errmsg} @tab intent(out) When an error occurs, this will be set to
5127 an error message; may be NULL.
5128 @item @var{errmsg_len} @tab intent(in) the buffer size of errmsg
5132 This function is also called for critical blocks; for those, the array index
5133 is always zero and the image index is one. Libraries are permitted to use other
5134 images for critical-block locking variables.
5137 @node _gfortran_caf_unlock
5138 @subsection @code{_gfortran_caf_lock} --- Unlocking a lock variable
5139 @cindex Coarray, _gfortran_caf_unlock
5142 @item @emph{Description}:
5143 Release a lock on the given image on a scalar locking variable or for the
5144 given array element for an array-valued variable. Unlocking a lock variable
5145 which is unlocked or has been locked by a different image is an error.
5147 @item @emph{Syntax}:
5148 @code{void _gfortran_caf_unlock (caf_token_t token, size_t index, int image_index,
5149 int *stat, char *errmsg, size_t errmsg_len)}
5151 @item @emph{Arguments}:
5152 @multitable @columnfractions .15 .70
5153 @item @var{token} @tab intent(in) An opaque pointer identifying the coarray.
5154 @item @var{index} @tab intent(in) Array index; first array index is 0. For
5155 scalars, it is always 0.
5156 @item @var{image_index} @tab intent(in) The ID of the remote image; must be a
5158 @item @var{stat} @tab intent(out) For allocatable coarrays, stores the STAT=;
5160 @item @var{errmsg} @tab intent(out) When an error occurs, this will be set to
5161 an error message; may be NULL.
5162 @item @var{errmsg_len} @tab intent(in) the buffer size of errmsg
5166 This function is also called for critical block; for those, the array index
5167 is always zero and the image index is one. Libraries are permitted to use other
5168 images for critical-block locking variables.
5171 @node _gfortran_caf_event_post
5172 @subsection @code{_gfortran_caf_event_post} --- Post an event
5173 @cindex Coarray, _gfortran_caf_event_post
5176 @item @emph{Description}:
5177 Increment the event count of the specified event variable.
5179 @item @emph{Syntax}:
5180 @code{void _gfortran_caf_event_post (caf_token_t token, size_t index,
5181 int image_index, int *stat, char *errmsg, size_t errmsg_len)}
5183 @item @emph{Arguments}:
5184 @multitable @columnfractions .15 .70
5185 @item @var{token} @tab intent(in) An opaque pointer identifying the coarray.
5186 @item @var{index} @tab intent(in) Array index; first array index is 0. For
5187 scalars, it is always 0.
5188 @item @var{image_index} @tab intent(in) The ID of the remote image; must be a
5189 positive number; zero indicates the current image, when accessed noncoindexed.
5190 @item @var{stat} @tab intent(out) Stores the STAT=; may be NULL.
5191 @item @var{errmsg} @tab intent(out) When an error occurs, this will be set to
5192 an error message; may be NULL.
5193 @item @var{errmsg_len} @tab intent(in) the buffer size of errmsg
5197 This acts like an atomic add of one to the remote image's event variable.
5198 The statement is an image-control statement but does not imply sync memory.
5199 Still, all preceeding push communications of this image to the specified
5200 remote image have to be completed before @code{event_wait} on the remote
5206 @node _gfortran_caf_event_wait
5207 @subsection @code{_gfortran_caf_event_wait} --- Wait that an event occurred
5208 @cindex Coarray, _gfortran_caf_event_wait
5211 @item @emph{Description}:
5212 Wait until the event count has reached at least the specified
5213 @var{until_count}; if so, atomically decrement the event variable by this
5216 @item @emph{Syntax}:
5217 @code{void _gfortran_caf_event_wait (caf_token_t token, size_t index,
5218 int until_count, int *stat, char *errmsg, size_t errmsg_len)}
5220 @item @emph{Arguments}:
5221 @multitable @columnfractions .15 .70
5222 @item @var{token} @tab intent(in) An opaque pointer identifying the coarray.
5223 @item @var{index} @tab intent(in) Array index; first array index is 0. For
5224 scalars, it is always 0.
5225 @item @var{until_count} @tab intent(in) The number of events which have to be
5226 available before the function returns.
5227 @item @var{stat} @tab intent(out) Stores the STAT=; may be NULL.
5228 @item @var{errmsg} @tab intent(out) When an error occurs, this will be set to
5229 an error message; may be NULL.
5230 @item @var{errmsg_len} @tab intent(in) the buffer size of errmsg
5234 This function only operates on a local coarray. It acts like a loop checking
5235 atomically the value of the event variable, breaking if the value is greater
5236 or equal the requested number of counts. Before the function returns, the
5237 event variable has to be decremented by the requested @var{until_count} value.
5238 A possible implementation would be a busy loop for a certain number of spins
5239 (possibly depending on the number of threads relative to the number of available
5240 cores) followed by another waiting strategy such as a sleeping wait (possibly
5241 with an increasing number of sleep time) or, if possible, a futex wait.
5243 The statement is an image-control statement but does not imply sync memory.
5244 Still, all preceeding push communications of this image to the specified
5245 remote image have to be completed before @code{event_wait} on the remote
5251 @node _gfortran_caf_event_query
5252 @subsection @code{_gfortran_caf_event_query} --- Query event count
5253 @cindex Coarray, _gfortran_caf_event_query
5256 @item @emph{Description}:
5257 Return the event count of the specified event variable.
5259 @item @emph{Syntax}:
5260 @code{void _gfortran_caf_event_query (caf_token_t token, size_t index,
5261 int image_index, int *count, int *stat)}
5263 @item @emph{Arguments}:
5264 @multitable @columnfractions .15 .70
5265 @item @var{token} @tab intent(in) An opaque pointer identifying the coarray.
5266 @item @var{index} @tab intent(in) Array index; first array index is 0. For
5267 scalars, it is always 0.
5268 @item @var{image_index} @tab intent(in) The ID of the remote image; must be a
5269 positive number; zero indicates the current image when accessed noncoindexed.
5270 @item @var{count} @tab intent(out) The number of events currently posted to
5272 @item @var{stat} @tab intent(out) Stores the STAT=; may be NULL.
5276 The typical use is to check the local event variable to only call
5277 @code{event_wait} when the data is available. However, a coindexed variable
5278 is permitted; there is no ordering or synchronization implied. It acts like
5279 an atomic fetch of the value of the event variable.
5284 @node _gfortran_caf_sync_all
5285 @subsection @code{_gfortran_caf_sync_all} --- All-image barrier
5286 @cindex Coarray, _gfortran_caf_sync_all
5289 @item @emph{Description}:
5290 Synchronization of all images in the current team; the program only continues
5291 on a given image after this function has been called on all images of the
5292 current team. Additionally, it ensures that all pending data transfers of
5293 previous segment have completed.
5295 @item @emph{Syntax}:
5296 @code{void _gfortran_caf_sync_all (int *stat, char *errmsg, size_t errmsg_len)}
5298 @item @emph{Arguments}:
5299 @multitable @columnfractions .15 .70
5300 @item @var{stat} @tab intent(out) Stores the status STAT= and may be NULL.
5301 @item @var{errmsg} @tab intent(out) When an error occurs, this will be set to
5302 an error message; may be NULL.
5303 @item @var{errmsg_len} @tab intent(in) the buffer size of errmsg
5309 @node _gfortran_caf_sync_images
5310 @subsection @code{_gfortran_caf_sync_images} --- Barrier for selected images
5311 @cindex Coarray, _gfortran_caf_sync_images
5314 @item @emph{Description}:
5315 Synchronization between the specified images; the program only continues on a
5316 given image after this function has been called on all images specified for
5317 that image. Note that one image can wait for all other images in the current
5318 team (e.g. via @code{sync images(*)}) while those only wait for that specific
5319 image. Additionally, @code{sync images} ensures that all pending data
5320 transfers of previous segments have completed.
5322 @item @emph{Syntax}:
5323 @code{void _gfortran_caf_sync_images (int count, int images[], int *stat,
5324 char *errmsg, size_t errmsg_len)}
5326 @item @emph{Arguments}:
5327 @multitable @columnfractions .15 .70
5328 @item @var{count} @tab intent(in) The number of images which are provided in
5329 the next argument. For a zero-sized array, the value is zero. For
5330 @code{sync images (*)}, the value is @math{-1}.
5331 @item @var{images} @tab intent(in) An array with the images provided by the
5332 user. If @var{count} is zero, a NULL pointer is passed.
5333 @item @var{stat} @tab intent(out) Stores the status STAT= and may be NULL.
5334 @item @var{errmsg} @tab intent(out) When an error occurs, this will be set to
5335 an error message; may be NULL.
5336 @item @var{errmsg_len} @tab intent(in) the buffer size of errmsg
5342 @node _gfortran_caf_sync_memory
5343 @subsection @code{_gfortran_caf_sync_memory} --- Wait for completion of segment-memory operations
5344 @cindex Coarray, _gfortran_caf_sync_memory
5347 @item @emph{Description}:
5348 Acts as optimization barrier between different segments. It also ensures that
5349 all pending memory operations of this image have been completed.
5351 @item @emph{Syntax}:
5352 @code{void _gfortran_caf_sync_memory (int *stat, char *errmsg, size_t errmsg_len)}
5354 @item @emph{Arguments}:
5355 @multitable @columnfractions .15 .70
5356 @item @var{stat} @tab intent(out) Stores the status STAT= and may be NULL.
5357 @item @var{errmsg} @tab intent(out) When an error occurs, this will be set to
5358 an error message; may be NULL.
5359 @item @var{errmsg_len} @tab intent(in) the buffer size of errmsg
5362 @item @emph{NOTE} A simple implementation could be
5363 @code{__asm__ __volatile__ ("":::"memory")} to prevent code movements.
5368 @node _gfortran_caf_error_stop
5369 @subsection @code{_gfortran_caf_error_stop} --- Error termination with exit code
5370 @cindex Coarray, _gfortran_caf_error_stop
5373 @item @emph{Description}:
5374 Invoked for an @code{ERROR STOP} statement which has an integer argument. The
5375 function should terminate the program with the specified exit code.
5378 @item @emph{Syntax}:
5379 @code{void _gfortran_caf_error_stop (int error)}
5381 @item @emph{Arguments}:
5382 @multitable @columnfractions .15 .70
5383 @item @var{error} @tab intent(in) The exit status to be used.
5389 @node _gfortran_caf_error_stop_str
5390 @subsection @code{_gfortran_caf_error_stop_str} --- Error termination with string
5391 @cindex Coarray, _gfortran_caf_error_stop_str
5394 @item @emph{Description}:
5395 Invoked for an @code{ERROR STOP} statement which has a string as argument. The
5396 function should terminate the program with a nonzero-exit code.
5398 @item @emph{Syntax}:
5399 @code{void _gfortran_caf_error_stop (const char *string, size_t len)}
5401 @item @emph{Arguments}:
5402 @multitable @columnfractions .15 .70
5403 @item @var{string} @tab intent(in) the error message (not zero terminated)
5404 @item @var{len} @tab intent(in) the length of the string
5410 @node _gfortran_caf_fail_image
5411 @subsection @code{_gfortran_caf_fail_image} --- Mark the image failed and end its execution
5412 @cindex Coarray, _gfortran_caf_fail_image
5415 @item @emph{Description}:
5416 Invoked for an @code{FAIL IMAGE} statement. The function should terminate the
5419 @item @emph{Syntax}:
5420 @code{void _gfortran_caf_fail_image ()}
5423 This function follows TS18508.
5428 @node _gfortran_caf_atomic_define
5429 @subsection @code{_gfortran_caf_atomic_define} --- Atomic variable assignment
5430 @cindex Coarray, _gfortran_caf_atomic_define
5433 @item @emph{Description}:
5434 Assign atomically a value to an integer or logical variable.
5436 @item @emph{Syntax}:
5437 @code{void _gfortran_caf_atomic_define (caf_token_t token, size_t offset,
5438 int image_index, void *value, int *stat, int type, int kind)}
5440 @item @emph{Arguments}:
5441 @multitable @columnfractions .15 .70
5442 @item @var{token} @tab intent(in) An opaque pointer identifying the coarray.
5443 @item @var{offset} @tab intent(in) By which amount of bytes the actual data is
5444 shifted compared to the base address of the coarray.
5445 @item @var{image_index} @tab intent(in) The ID of the remote image; must be a
5446 positive number; zero indicates the current image when used noncoindexed.
5447 @item @var{value} @tab intent(in) the value to be assigned, passed by reference
5448 @item @var{stat} @tab intent(out) Stores the status STAT= and may be NULL.
5449 @item @var{type} @tab intent(in) The data type, i.e. @code{BT_INTEGER} (1) or
5450 @code{BT_LOGICAL} (2).
5451 @item @var{kind} @tab intent(in) The kind value (only 4; always @code{int})
5457 @node _gfortran_caf_atomic_ref
5458 @subsection @code{_gfortran_caf_atomic_ref} --- Atomic variable reference
5459 @cindex Coarray, _gfortran_caf_atomic_ref
5462 @item @emph{Description}:
5463 Reference atomically a value of a kind-4 integer or logical variable.
5465 @item @emph{Syntax}:
5466 @code{void _gfortran_caf_atomic_ref (caf_token_t token, size_t offset,
5467 int image_index, void *value, int *stat, int type, int kind)}
5469 @item @emph{Arguments}:
5470 @multitable @columnfractions .15 .70
5471 @item @var{token} @tab intent(in) An opaque pointer identifying the coarray.
5472 @item @var{offset} @tab intent(in) By which amount of bytes the actual data is
5473 shifted compared to the base address of the coarray.
5474 @item @var{image_index} @tab intent(in) The ID of the remote image; must be a
5475 positive number; zero indicates the current image when used noncoindexed.
5476 @item @var{value} @tab intent(out) The variable assigned the atomically
5477 referenced variable.
5478 @item @var{stat} @tab intent(out) Stores the status STAT= and may be NULL.
5479 @item @var{type} @tab the data type, i.e. @code{BT_INTEGER} (1) or
5480 @code{BT_LOGICAL} (2).
5481 @item @var{kind} @tab The kind value (only 4; always @code{int})
5487 @node _gfortran_caf_atomic_cas
5488 @subsection @code{_gfortran_caf_atomic_cas} --- Atomic compare and swap
5489 @cindex Coarray, _gfortran_caf_atomic_cas
5492 @item @emph{Description}:
5493 Atomic compare and swap of a kind-4 integer or logical variable. Assigns
5494 atomically the specified value to the atomic variable, if the latter has
5495 the value specified by the passed condition value.
5497 @item @emph{Syntax}:
5498 @code{void _gfortran_caf_atomic_cas (caf_token_t token, size_t offset,
5499 int image_index, void *old, void *compare, void *new_val, int *stat,
5500 int type, int kind)}
5502 @item @emph{Arguments}:
5503 @multitable @columnfractions .15 .70
5504 @item @var{token} @tab intent(in) An opaque pointer identifying the coarray.
5505 @item @var{offset} @tab intent(in) By which amount of bytes the actual data is
5506 shifted compared to the base address of the coarray.
5507 @item @var{image_index} @tab intent(in) The ID of the remote image; must be a
5508 positive number; zero indicates the current image when used noncoindexed.
5509 @item @var{old} @tab intent(out) The value which the atomic variable had
5510 just before the cas operation.
5511 @item @var{compare} @tab intent(in) The value used for comparision.
5512 @item @var{new_val} @tab intent(in) The new value for the atomic variable,
5513 assigned to the atomic variable, if @code{compare} equals the value of the
5515 @item @var{stat} @tab intent(out) Stores the status STAT= and may be NULL.
5516 @item @var{type} @tab intent(in) the data type, i.e. @code{BT_INTEGER} (1) or
5517 @code{BT_LOGICAL} (2).
5518 @item @var{kind} @tab intent(in) The kind value (only 4; always @code{int})
5524 @node _gfortran_caf_atomic_op
5525 @subsection @code{_gfortran_caf_atomic_op} --- Atomic operation
5526 @cindex Coarray, _gfortran_caf_atomic_op
5529 @item @emph{Description}:
5530 Apply an operation atomically to an atomic integer or logical variable.
5531 After the operation, @var{old} contains the value just before the operation,
5532 which, respectively, adds (GFC_CAF_ATOMIC_ADD) atomically the @code{value} to
5533 the atomic integer variable or does a bitwise AND, OR or exclusive OR
5534 between the atomic variable and @var{value}; the result is then stored in the
5537 @item @emph{Syntax}:
5538 @code{void _gfortran_caf_atomic_op (int op, caf_token_t token, size_t offset,
5539 int image_index, void *value, void *old, int *stat, int type, int kind)}
5541 @item @emph{Arguments}:
5542 @multitable @columnfractions .15 .70
5543 @item @var{op} @tab intent(in) the operation to be performed; possible values
5544 @code{GFC_CAF_ATOMIC_ADD} (1), @code{GFC_CAF_ATOMIC_AND} (2),
5545 @code{GFC_CAF_ATOMIC_OR} (3), @code{GFC_CAF_ATOMIC_XOR} (4).
5546 @item @var{token} @tab intent(in) An opaque pointer identifying the coarray.
5547 @item @var{offset} @tab intent(in) By which amount of bytes the actual data is
5548 shifted compared to the base address of the coarray.
5549 @item @var{image_index} @tab intent(in) The ID of the remote image; must be a
5550 positive number; zero indicates the current image when used noncoindexed.
5551 @item @var{old} @tab intent(out) The value which the atomic variable had
5552 just before the atomic operation.
5553 @item @var{val} @tab intent(in) The new value for the atomic variable,
5554 assigned to the atomic variable, if @code{compare} equals the value of the
5556 @item @var{stat} @tab intent(out) Stores the status STAT= and may be NULL.
5557 @item @var{type} @tab intent(in) the data type, i.e. @code{BT_INTEGER} (1) or
5558 @code{BT_LOGICAL} (2)
5559 @item @var{kind} @tab intent(in) the kind value (only 4; always @code{int})
5566 @node _gfortran_caf_co_broadcast
5567 @subsection @code{_gfortran_caf_co_broadcast} --- Sending data to all images
5568 @cindex Coarray, _gfortran_caf_co_broadcast
5571 @item @emph{Description}:
5572 Distribute a value from a given image to all other images in the team. Has to
5573 be called collectively.
5575 @item @emph{Syntax}:
5576 @code{void _gfortran_caf_co_broadcast (gfc_descriptor_t *a,
5577 int source_image, int *stat, char *errmsg, size_t errmsg_len)}
5579 @item @emph{Arguments}:
5580 @multitable @columnfractions .15 .70
5581 @item @var{a} @tab intent(inout) An array descriptor with the data to be
5582 broadcasted (on @var{source_image}) or to be received (other images).
5583 @item @var{source_image} @tab intent(in) The ID of the image from which the
5584 data should be broadcasted.
5585 @item @var{stat} @tab intent(out) Stores the status STAT= and may be NULL.
5586 @item @var{errmsg} @tab intent(out) When an error occurs, this will be set to
5587 an error message; may be NULL.
5588 @item @var{errmsg_len} @tab intent(in) the buffer size of errmsg.
5594 @node _gfortran_caf_co_max
5595 @subsection @code{_gfortran_caf_co_max} --- Collective maximum reduction
5596 @cindex Coarray, _gfortran_caf_co_max
5599 @item @emph{Description}:
5600 Calculates for each array element of the variable @var{a} the maximum
5601 value for that element in the current team; if @var{result_image} has the
5602 value 0, the result shall be stored on all images, otherwise, only on the
5603 specified image. This function operates on numeric values and character
5606 @item @emph{Syntax}:
5607 @code{void _gfortran_caf_co_max (gfc_descriptor_t *a, int result_image,
5608 int *stat, char *errmsg, int a_len, size_t errmsg_len)}
5610 @item @emph{Arguments}:
5611 @multitable @columnfractions .15 .70
5612 @item @var{a} @tab intent(inout) An array descriptor for the data to be
5613 processed. On the destination image(s) the result overwrites the old content.
5614 @item @var{result_image} @tab intent(in) The ID of the image to which the
5615 reduced value should be copied to; if zero, it has to be copied to all images.
5616 @item @var{stat} @tab intent(out) Stores the status STAT= and may be NULL.
5617 @item @var{errmsg} @tab intent(out) When an error occurs, this will be set to
5618 an error message; may be NULL.
5619 @item @var{a_len} @tab intent(in) the string length of argument @var{a}
5620 @item @var{errmsg_len} @tab intent(in) the buffer size of errmsg
5624 If @var{result_image} is nonzero, the data in the array descriptor @var{a} on
5625 all images except of the specified one become undefined; hence, the library may
5631 @node _gfortran_caf_co_min
5632 @subsection @code{_gfortran_caf_co_min} --- Collective minimum reduction
5633 @cindex Coarray, _gfortran_caf_co_min
5636 @item @emph{Description}:
5637 Calculates for each array element of the variable @var{a} the minimum
5638 value for that element in the current team; if @var{result_image} has the
5639 value 0, the result shall be stored on all images, otherwise, only on the
5640 specified image. This function operates on numeric values and character
5643 @item @emph{Syntax}:
5644 @code{void _gfortran_caf_co_min (gfc_descriptor_t *a, int result_image,
5645 int *stat, char *errmsg, int a_len, size_t errmsg_len)}
5647 @item @emph{Arguments}:
5648 @multitable @columnfractions .15 .70
5649 @item @var{a} @tab intent(inout) An array descriptor for the data to be
5650 processed. On the destination image(s) the result overwrites the old content.
5651 @item @var{result_image} @tab intent(in) The ID of the image to which the
5652 reduced value should be copied to; if zero, it has to be copied to all images.
5653 @item @var{stat} @tab intent(out) Stores the status STAT= and may be NULL.
5654 @item @var{errmsg} @tab intent(out) When an error occurs, this will be set to
5655 an error message; may be NULL.
5656 @item @var{a_len} @tab intent(in) the string length of argument @var{a}
5657 @item @var{errmsg_len} @tab intent(in) the buffer size of errmsg
5661 If @var{result_image} is nonzero, the data in the array descriptor @var{a} on
5662 all images except of the specified one become undefined; hence, the library may
5668 @node _gfortran_caf_co_sum
5669 @subsection @code{_gfortran_caf_co_sum} --- Collective summing reduction
5670 @cindex Coarray, _gfortran_caf_co_sum
5673 @item @emph{Description}:
5674 Calculates for each array element of the variable @var{a} the sum of all
5675 values for that element in the current team; if @var{result_image} has the
5676 value 0, the result shall be stored on all images, otherwise, only on the
5677 specified image. This function operates on numeric values only.
5679 @item @emph{Syntax}:
5680 @code{void _gfortran_caf_co_sum (gfc_descriptor_t *a, int result_image,
5681 int *stat, char *errmsg, size_t errmsg_len)}
5683 @item @emph{Arguments}:
5684 @multitable @columnfractions .15 .70
5685 @item @var{a} @tab intent(inout) An array descriptor with the data to be
5686 processed. On the destination image(s) the result overwrites the old content.
5687 @item @var{result_image} @tab intent(in) The ID of the image to which the
5688 reduced value should be copied to; if zero, it has to be copied to all images.
5689 @item @var{stat} @tab intent(out) Stores the status STAT= and may be NULL.
5690 @item @var{errmsg} @tab intent(out) When an error occurs, this will be set to
5691 an error message; may be NULL.
5692 @item @var{errmsg_len} @tab intent(in) the buffer size of errmsg
5696 If @var{result_image} is nonzero, the data in the array descriptor @var{a} on
5697 all images except of the specified one become undefined; hence, the library may
5703 @node _gfortran_caf_co_reduce
5704 @subsection @code{_gfortran_caf_co_reduce} --- Generic collective reduction
5705 @cindex Coarray, _gfortran_caf_co_reduce
5708 @item @emph{Description}:
5709 Calculates for each array element of the variable @var{a} the reduction
5710 value for that element in the current team; if @var{result_image} has the
5711 value 0, the result shall be stored on all images, otherwise, only on the
5712 specified image. The @var{opr} is a pure function doing a mathematically
5713 commutative and associative operation.
5715 The @var{opr_flags} denote the following; the values are bitwise ored.
5716 @code{GFC_CAF_BYREF} (1) if the result should be returned
5717 by reference; @code{GFC_CAF_HIDDENLEN} (2) whether the result and argument
5718 string lengths shall be specified as hidden arguments;
5719 @code{GFC_CAF_ARG_VALUE} (4) whether the arguments shall be passed by value,
5720 @code{GFC_CAF_ARG_DESC} (8) whether the arguments shall be passed by descriptor.
5723 @item @emph{Syntax}:
5724 @code{void _gfortran_caf_co_reduce (gfc_descriptor_t *a,
5725 void * (*opr) (void *, void *), int opr_flags, int result_image,
5726 int *stat, char *errmsg, int a_len, size_t errmsg_len)}
5728 @item @emph{Arguments}:
5729 @multitable @columnfractions .15 .70
5730 @item @var{a} @tab intent(inout) An array descriptor with the data to be
5731 processed. On the destination image(s) the result overwrites the old content.
5732 @item @var{opr} @tab intent(in) Function pointer to the reduction function
5733 @item @var{opr_flags} @tab intent(in) Flags regarding the reduction function
5734 @item @var{result_image} @tab intent(in) The ID of the image to which the
5735 reduced value should be copied to; if zero, it has to be copied to all images.
5736 @item @var{stat} @tab intent(out) Stores the status STAT= and may be NULL.
5737 @item @var{errmsg} @tab intent(out) When an error occurs, this will be set to
5738 an error message; may be NULL.
5739 @item @var{a_len} @tab intent(in) the string length of argument @var{a}
5740 @item @var{errmsg_len} @tab intent(in) the buffer size of errmsg
5744 If @var{result_image} is nonzero, the data in the array descriptor @var{a} on
5745 all images except of the specified one become undefined; hence, the library may
5748 For character arguments, the result is passed as first argument, followed
5749 by the result string length, next come the two string arguments, followed
5750 by the two hidden string length arguments. With C binding, there are no hidden
5751 arguments and by-reference passing and either only a single character is passed
5752 or an array descriptor.
5756 @c Intrinsic Procedures
5757 @c ---------------------------------------------------------------------
5759 @include intrinsic.texi
5766 @c ---------------------------------------------------------------------
5768 @c ---------------------------------------------------------------------
5771 @unnumbered Contributing
5772 @cindex Contributing
5774 Free software is only possible if people contribute to efforts
5776 We're always in need of more people helping out with ideas
5777 and comments, writing documentation and contributing code.
5779 If you want to contribute to GNU Fortran,
5780 have a look at the long lists of projects you can take on.
5781 Some of these projects are small,
5782 some of them are large;
5783 some are completely orthogonal to the rest of what is
5784 happening on GNU Fortran,
5785 but others are ``mainstream'' projects in need of enthusiastic hackers.
5786 All of these projects are important!
5787 We will eventually get around to the things here,
5788 but they are also things doable by someone who is willing and able.
5793 * Proposed Extensions::
5798 @section Contributors to GNU Fortran
5799 @cindex Contributors
5803 Most of the parser was hand-crafted by @emph{Andy Vaught}, who is
5804 also the initiator of the whole project. Thanks Andy!
5805 Most of the interface with GCC was written by @emph{Paul Brook}.
5807 The following individuals have contributed code and/or
5808 ideas and significant help to the GNU Fortran project
5809 (in alphabetical order):
5812 @item Janne Blomqvist
5813 @item Steven Bosscher
5816 @item Fran@,{c}ois-Xavier Coudert
5820 @item Bernhard Fischer
5822 @item Richard Guenther
5823 @item Richard Henderson
5824 @item Katherine Holcomb
5826 @item Niels Kristian Bech Jensen
5827 @item Steven Johnson
5828 @item Steven G. Kargl
5836 @item Christopher D. Rickett
5837 @item Richard Sandiford
5838 @item Tobias Schl@"uter
5847 The following people have contributed bug reports,
5848 smaller or larger patches,
5849 and much needed feedback and encouragement for the
5850 GNU Fortran project:
5854 @item Dominique d'Humi@`eres
5856 @item Erik Schnetter
5857 @item Joost VandeVondele
5860 Many other individuals have helped debug,
5861 test and improve the GNU Fortran compiler over the past few years,
5862 and we welcome you to do the same!
5863 If you already have done so,
5864 and you would like to see your name listed in the
5865 list above, please contact us.
5873 @item Help build the test suite
5874 Solicit more code for donation to the test suite: the more extensive the
5875 testsuite, the smaller the risk of breaking things in the future! We can
5876 keep code private on request.
5878 @item Bug hunting/squishing
5879 Find bugs and write more test cases! Test cases are especially very
5880 welcome, because it allows us to concentrate on fixing bugs instead of
5881 isolating them. Going through the bugzilla database at
5882 @url{https://gcc.gnu.org/@/bugzilla/} to reduce testcases posted there and
5883 add more information (for example, for which version does the testcase
5884 work, for which versions does it fail?) is also very helpful.
5889 @node Proposed Extensions
5890 @section Proposed Extensions
5892 Here's a list of proposed extensions for the GNU Fortran compiler, in no particular
5893 order. Most of these are necessary to be fully compatible with
5894 existing Fortran compilers, but they are not part of the official
5895 J3 Fortran 95 standard.
5897 @subsection Compiler extensions:
5900 User-specified alignment rules for structures.
5903 Automatically extend single precision constants to double.
5906 Compile code that conserves memory by dynamically allocating common and
5907 module storage either on stack or heap.
5910 Compile flag to generate code for array conformance checking (suggest -CC).
5913 User control of symbol names (underscores, etc).
5916 Compile setting for maximum size of stack frame size before spilling
5917 parts to static or heap.
5920 Flag to force local variables into static space.
5923 Flag to force local variables onto stack.
5927 @subsection Environment Options
5930 Pluggable library modules for random numbers, linear algebra.
5931 LA should use BLAS calling conventions.
5934 Environment variables controlling actions on arithmetic exceptions like
5935 overflow, underflow, precision loss---Generate NaN, abort, default.
5939 Set precision for fp units that support it (i387).
5942 Variable for setting fp rounding mode.
5945 Variable to fill uninitialized variables with a user-defined bit
5949 Environment variable controlling filename that is opened for that unit
5953 Environment variable to clear/trash memory being freed.
5956 Environment variable to control tracing of allocations and frees.
5959 Environment variable to display allocated memory at normal program end.
5962 Environment variable for filename for * IO-unit.
5965 Environment variable for temporary file directory.
5968 Environment variable forcing standard output to be line buffered (Unix).
5973 @c ---------------------------------------------------------------------
5974 @c GNU General Public License
5975 @c ---------------------------------------------------------------------
5977 @include gpl_v3.texi
5981 @c ---------------------------------------------------------------------
5982 @c GNU Free Documentation License
5983 @c ---------------------------------------------------------------------
5989 @c ---------------------------------------------------------------------
5990 @c Funding Free Software
5991 @c ---------------------------------------------------------------------
5993 @include funding.texi
5995 @c ---------------------------------------------------------------------
5997 @c ---------------------------------------------------------------------
6000 @unnumbered Option Index
6001 @command{gfortran}'s command line options are indexed here without any
6002 initial @samp{-} or @samp{--}. Where an option has both positive and
6003 negative forms (such as -foption and -fno-option), relevant entries in
6004 the manual are indexed under the most appropriate form; it may sometimes
6005 be useful to look up both forms.
6009 @unnumbered Keyword Index