]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/fortran/gfortran.texi
d6bb7aae49478fdd233d79e3d068e327bfe8e0d4
[thirdparty/gcc.git] / gcc / fortran / gfortran.texi
1 \input texinfo @c -*-texinfo-*-
2 @c %**start of header
3 @setfilename gfortran.info
4 @set copyrights-gfortran 1999-2018
5
6 @include gcc-common.texi
7
8 @settitle The GNU Fortran Compiler
9
10 @c Create a separate index for command line options
11 @defcodeindex op
12 @c Merge the standard indexes into a single one.
13 @syncodeindex fn cp
14 @syncodeindex vr cp
15 @syncodeindex ky cp
16 @syncodeindex pg cp
17 @syncodeindex tp cp
18
19 @c TODO: The following "Part" definitions are included here temporarily
20 @c until they are incorporated into the official Texinfo distribution.
21 @c They borrow heavily from Texinfo's \unnchapentry definitions.
22
23 @tex
24 \gdef\part#1#2{%
25 \pchapsepmacro
26 \gdef\thischapter{}
27 \begingroup
28 \vglue\titlepagetopglue
29 \titlefonts \rm
30 \leftline{Part #1:@* #2}
31 \vskip4pt \hrule height 4pt width \hsize \vskip4pt
32 \endgroup
33 \writetocentry{part}{#2}{#1}
34 }
35 \gdef\blankpart{%
36 \writetocentry{blankpart}{}{}
37 }
38 % Part TOC-entry definition for summary contents.
39 \gdef\dosmallpartentry#1#2#3#4{%
40 \vskip .5\baselineskip plus.2\baselineskip
41 \begingroup
42 \let\rm=\bf \rm
43 \tocentry{Part #2: #1}{\doshortpageno\bgroup#4\egroup}
44 \endgroup
45 }
46 \gdef\dosmallblankpartentry#1#2#3#4{%
47 \vskip .5\baselineskip plus.2\baselineskip
48 }
49 % Part TOC-entry definition for regular contents. This has to be
50 % equated to an existing entry to not cause problems when the PDF
51 % outline is created.
52 \gdef\dopartentry#1#2#3#4{%
53 \unnchapentry{Part #2: #1}{}{#3}{#4}
54 }
55 \gdef\doblankpartentry#1#2#3#4{}
56 @end tex
57
58 @c %**end of header
59
60 @c Use with @@smallbook.
61
62 @c %** start of document
63
64 @c Cause even numbered pages to be printed on the left hand side of
65 @c the page and odd numbered pages to be printed on the right hand
66 @c side of the page. Using this, you can print on both sides of a
67 @c sheet of paper and have the text on the same part of the sheet.
68
69 @c The text on right hand pages is pushed towards the right hand
70 @c margin and the text on left hand pages is pushed toward the left
71 @c hand margin.
72 @c (To provide the reverse effect, set bindingoffset to -0.75in.)
73
74 @c @tex
75 @c \global\bindingoffset=0.75in
76 @c \global\normaloffset =0.75in
77 @c @end tex
78
79 @copying
80 Copyright @copyright{} @value{copyrights-gfortran} Free Software Foundation, Inc.
81
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''.
89
90 (a) The FSF's Front-Cover Text is:
91
92 A GNU Manual
93
94 (b) The FSF's Back-Cover Text is:
95
96 You have freedom to copy and modify this GNU Manual, like GNU
97 software. Copies published by the Free Software Foundation raise
98 funds for GNU development.
99 @end copying
100
101 @ifinfo
102 @dircategory Software development
103 @direntry
104 * gfortran: (gfortran). The GNU Fortran Compiler.
105 @end direntry
106 This file documents the use and the internals of
107 the GNU Fortran compiler, (@command{gfortran}).
108
109 Published by the Free Software Foundation
110 51 Franklin Street, Fifth Floor
111 Boston, MA 02110-1301 USA
112
113 @insertcopying
114 @end ifinfo
115
116
117 @setchapternewpage odd
118 @titlepage
119 @title Using GNU Fortran
120 @versionsubtitle
121 @author The @t{gfortran} team
122 @page
123 @vskip 0pt plus 1filll
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.@*
129 @c ISBN ???
130 @sp 1
131 @insertcopying
132 @end titlepage
133
134 @c TODO: The following "Part" definitions are included here temporarily
135 @c until they are incorporated into the official Texinfo distribution.
136
137 @tex
138 \global\let\partentry=\dosmallpartentry
139 \global\let\blankpartentry=\dosmallblankpartentry
140 @end tex
141 @summarycontents
142
143 @tex
144 \global\let\partentry=\dopartentry
145 \global\let\blankpartentry=\doblankpartentry
146 @end tex
147 @contents
148
149 @page
150
151 @c ---------------------------------------------------------------------
152 @c TexInfo table of contents.
153 @c ---------------------------------------------------------------------
154
155 @ifnottex
156 @node Top
157 @top Introduction
158 @cindex Introduction
159
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.
163
164 @ifset DEVELOPMENT
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.
168 @end ifset
169
170 @comment
171 @comment When you add a new menu item, please keep the right hand
172 @comment aligned to the same column. Do not use tabs. This provides
173 @comment better formatting.
174 @comment
175 @menu
176 * Introduction::
177
178 Part I: Invoking GNU Fortran
179 * Invoking GNU Fortran:: Command options supported by @command{gfortran}.
180 * Runtime:: Influencing runtime behavior with environment variables.
181
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.
190
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
199 @end menu
200 @end ifnottex
201
202 @c ---------------------------------------------------------------------
203 @c Introduction
204 @c ---------------------------------------------------------------------
205
206 @node Introduction
207 @chapter Introduction
208
209 @c The following duplicates the text on the TexInfo table of contents.
210 @iftex
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.
214
215 @ifset DEVELOPMENT
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
219 compiler.
220 @end ifset
221 @end iftex
222
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.
227
228 @menu
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.
235 @end menu
236
237
238 @c ---------------------------------------------------------------------
239 @c About GNU Fortran
240 @c ---------------------------------------------------------------------
241
242 @node About GNU Fortran
243 @section About GNU Fortran
244
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
248 following features:
249
250 @itemize @bullet
251 @item
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}.
255
256 @item
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
261 @dfn{machine code},
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.
267
268 @item
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}.
275
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}.
280
281 @item
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.
288
289 @item
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}).
293
294 @item
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.
299 @end itemize
300
301 The GNU Fortran compiler consists of several components:
302
303 @itemize @bullet
304 @item
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);
310 With @command{gcc},
311 you can compile the source code of any language for
312 which a front end is available in GCC.
313
314 @item
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.
322
323 @item
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.
333
334 @item
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
340 program directly;
341 instead, the @command{gcc} or @command{gfortran} driver
342 programs will call it for you.
343 @end itemize
344
345
346 @c ---------------------------------------------------------------------
347 @c GNU Fortran and GCC
348 @c ---------------------------------------------------------------------
349
350 @node GNU Fortran and GCC
351 @section GNU Fortran and GCC
352 @cindex GNU Compiler Collection
353 @cindex GCC
354
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
361 operating systems.
362
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
374 compiled program.
375
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.
383
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
390 Fortran compiler.
391
392
393 @c ---------------------------------------------------------------------
394 @c Preprocessing and conditional compilation
395 @c ---------------------------------------------------------------------
396
397 @node Preprocessing and conditional compilation
398 @section Preprocessing and conditional compilation
399 @cindex CPP
400 @cindex FPP
401 @cindex Conditional compilation
402 @cindex Preprocessing
403 @cindex preprocessor, include file handling
404
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
414 @option{-nocpp}.
415
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}.
419
420 If GNU Fortran invokes the preprocessor, @code{__GFORTRAN__}
421 is defined and @code{__GNUC__}, @code{__GNUC_MINOR__} and
422 @code{__GNUC_PATCHLEVEL__} can be used to determine the version of the
423 compiler. See @ref{Top,,Overview,cpp,The C Preprocessor} for details.
424
425 While CPP is the de-facto standard for preprocessing Fortran code,
426 Part 3 of the Fortran 95 standard (ISO/IEC 1539-3:1998) defines
427 Conditional Compilation, which is not widely used and not directly
428 supported by the GNU Fortran compiler. You can use the program coco
429 to preprocess such files (@uref{http://www.daniellnagle.com/coco.html}).
430
431
432 @c ---------------------------------------------------------------------
433 @c GNU Fortran and G77
434 @c ---------------------------------------------------------------------
435
436 @node GNU Fortran and G77
437 @section GNU Fortran and G77
438 @cindex Fortran 77
439 @cindex @command{g77}
440
441 The GNU Fortran compiler is the successor to @command{g77}, the Fortran
442 77 front end included in GCC prior to version 4. It is an entirely new
443 program that has been designed to provide Fortran 95 support and
444 extensibility for future Fortran language standards, as well as providing
445 backwards compatibility for Fortran 77 and nearly all of the GNU language
446 extensions supported by @command{g77}.
447
448
449 @c ---------------------------------------------------------------------
450 @c Project Status
451 @c ---------------------------------------------------------------------
452
453 @node Project Status
454 @section Project Status
455
456 @quotation
457 As soon as @command{gfortran} can parse all of the statements correctly,
458 it will be in the ``larva'' state.
459 When we generate code, the ``puppa'' state.
460 When @command{gfortran} is done,
461 we'll see if it will be a beautiful butterfly,
462 or just a big bug....
463
464 --Andy Vaught, April 2000
465 @end quotation
466
467 The start of the GNU Fortran 95 project was announced on
468 the GCC homepage in March 18, 2000
469 (even though Andy had already been working on it for a while,
470 of course).
471
472 The GNU Fortran compiler is able to compile nearly all
473 standard-compliant Fortran 95, Fortran 90, and Fortran 77 programs,
474 including a number of standard and non-standard extensions, and can be
475 used on real-world programs. In particular, the supported extensions
476 include OpenMP, Cray-style pointers, some old vendor extensions, and several
477 Fortran 2003 and Fortran 2008 features, including TR 15581. However, it is
478 still under development and has a few remaining rough edges.
479 There also is initial support for OpenACC.
480 Note that this is an experimental feature, incomplete, and subject to
481 change in future versions of GCC. See
482 @uref{https://gcc.gnu.org/wiki/OpenACC} for more information.
483
484 At present, the GNU Fortran compiler passes the
485 @uref{http://www.fortran-2000.com/ArnaudRecipes/fcvs21_f95.html,
486 NIST Fortran 77 Test Suite}, and produces acceptable results on the
487 @uref{http://www.netlib.org/lapack/faq.html#1.21, LAPACK Test Suite}.
488 It also provides respectable performance on
489 the @uref{http://www.polyhedron.com/fortran-compiler-comparisons/polyhedron-benchmark-suite,
490 Polyhedron Fortran
491 compiler benchmarks} and the
492 @uref{http://www.netlib.org/benchmark/livermore,
493 Livermore Fortran Kernels test}. It has been used to compile a number of
494 large real-world programs, including
495 @uref{http://hirlam.org/, the HARMONIE and HIRLAM weather forecasting code} and
496 @uref{http://physical-chemistry.scb.uwa.edu.au/tonto/wiki/index.php/Main_Page,
497 the Tonto quantum chemistry package}; see
498 @url{https://gcc.gnu.org/@/wiki/@/GfortranApps} for an extended list.
499
500 Among other things, the GNU Fortran compiler is intended as a replacement
501 for G77. At this point, nearly all programs that could be compiled with
502 G77 can be compiled with GNU Fortran, although there are a few minor known
503 regressions.
504
505 The primary work remaining to be done on GNU Fortran falls into three
506 categories: bug fixing (primarily regarding the treatment of invalid
507 code and providing useful error messages), improving the compiler
508 optimizations and the performance of compiled code, and extending the
509 compiler to support future standards---in particular, Fortran 2003,
510 Fortran 2008 and Fortran 2018.
511
512
513 @c ---------------------------------------------------------------------
514 @c Standards
515 @c ---------------------------------------------------------------------
516
517 @node Standards
518 @section Standards
519 @cindex Standards
520
521 @menu
522 * Varying Length Character Strings::
523 @end menu
524
525 The GNU Fortran compiler implements
526 ISO/IEC 1539:1997 (Fortran 95). As such, it can also compile essentially all
527 standard-compliant Fortran 90 and Fortran 77 programs. It also supports
528 the ISO/IEC TR-15581 enhancements to allocatable arrays.
529
530 GNU Fortran also have a partial support for ISO/IEC 1539-1:2004
531 (Fortran 2003), ISO/IEC 1539-1:2010 (Fortran 2008), the Technical
532 Specification @code{Further Interoperability of Fortran with C}
533 (ISO/IEC TS 29113:2012). Full support of those standards and future
534 Fortran standards is planned. The current status of the support is
535 can be found in the @ref{Fortran 2003 status}, @ref{Fortran 2008
536 status} and @ref{Fortran 2018 status} sections of the documentation.
537
538 Additionally, the GNU Fortran compilers supports the OpenMP specification
539 (version 4.0 and most of the features of the 4.5 version,
540 @url{http://openmp.org/@/wp/@/openmp-specifications/}).
541 There also is initial support for the OpenACC specification (targeting
542 version 2.0, @uref{http://www.openacc.org/}).
543 Note that this is an experimental feature, incomplete, and subject to
544 change in future versions of GCC. See
545 @uref{https://gcc.gnu.org/wiki/OpenACC} for more information.
546
547 @node Varying Length Character Strings
548 @subsection Varying Length Character Strings
549 @cindex Varying length character strings
550 @cindex Varying length strings
551 @cindex strings, varying length
552
553 The Fortran 95 standard specifies in Part 2 (ISO/IEC 1539-2:2000)
554 varying length character strings. While GNU Fortran currently does not
555 support such strings directly, there exist two Fortran implementations
556 for them, which work with GNU Fortran. They can be found at
557 @uref{http://www.fortran.com/@/iso_varying_string.f95} and at
558 @uref{ftp://ftp.nag.co.uk/@/sc22wg5/@/ISO_VARYING_STRING/}.
559
560 Deferred-length character strings of Fortran 2003 supports part of
561 the features of @code{ISO_VARYING_STRING} and should be considered as
562 replacement. (Namely, allocatable or pointers of the type
563 @code{character(len=:)}.)
564
565
566 @c =====================================================================
567 @c PART I: INVOCATION REFERENCE
568 @c =====================================================================
569
570 @tex
571 \part{I}{Invoking GNU Fortran}
572 @end tex
573
574 @c ---------------------------------------------------------------------
575 @c Compiler Options
576 @c ---------------------------------------------------------------------
577
578 @include invoke.texi
579
580
581 @c ---------------------------------------------------------------------
582 @c Runtime
583 @c ---------------------------------------------------------------------
584
585 @node Runtime
586 @chapter Runtime: Influencing runtime behavior with environment variables
587 @cindex environment variable
588
589 The behavior of the @command{gfortran} can be influenced by
590 environment variables.
591
592 Malformed environment variables are silently ignored.
593
594 @menu
595 * TMPDIR:: Directory for scratch files
596 * GFORTRAN_STDIN_UNIT:: Unit number for standard input
597 * GFORTRAN_STDOUT_UNIT:: Unit number for standard output
598 * GFORTRAN_STDERR_UNIT:: Unit number for standard error
599 * GFORTRAN_UNBUFFERED_ALL:: Do not buffer I/O for all units.
600 * GFORTRAN_UNBUFFERED_PRECONNECTED:: Do not buffer I/O for preconnected units.
601 * GFORTRAN_SHOW_LOCUS:: Show location for runtime errors
602 * GFORTRAN_OPTIONAL_PLUS:: Print leading + where permitted
603 * GFORTRAN_LIST_SEPARATOR:: Separator for list output
604 * GFORTRAN_CONVERT_UNIT:: Set endianness for unformatted I/O
605 * GFORTRAN_ERROR_BACKTRACE:: Show backtrace on run-time errors
606 @end menu
607
608 @node TMPDIR
609 @section @env{TMPDIR}---Directory for scratch files
610
611 When opening a file with @code{STATUS='SCRATCH'}, GNU Fortran tries to
612 create the file in one of the potential directories by testing each
613 directory in the order below.
614
615 @enumerate
616 @item
617 The environment variable @env{TMPDIR}, if it exists.
618
619 @item
620 On the MinGW target, the directory returned by the @code{GetTempPath}
621 function. Alternatively, on the Cygwin target, the @env{TMP} and
622 @env{TEMP} environment variables, if they exist, in that order.
623
624 @item
625 The @code{P_tmpdir} macro if it is defined, otherwise the directory
626 @file{/tmp}.
627 @end enumerate
628
629 @node GFORTRAN_STDIN_UNIT
630 @section @env{GFORTRAN_STDIN_UNIT}---Unit number for standard input
631
632 This environment variable can be used to select the unit number
633 preconnected to standard input. This must be a positive integer.
634 The default value is 5.
635
636 @node GFORTRAN_STDOUT_UNIT
637 @section @env{GFORTRAN_STDOUT_UNIT}---Unit number for standard output
638
639 This environment variable can be used to select the unit number
640 preconnected to standard output. This must be a positive integer.
641 The default value is 6.
642
643 @node GFORTRAN_STDERR_UNIT
644 @section @env{GFORTRAN_STDERR_UNIT}---Unit number for standard error
645
646 This environment variable can be used to select the unit number
647 preconnected to standard error. This must be a positive integer.
648 The default value is 0.
649
650 @node GFORTRAN_UNBUFFERED_ALL
651 @section @env{GFORTRAN_UNBUFFERED_ALL}---Do not buffer I/O on all units
652
653 This environment variable controls whether all I/O is unbuffered. If
654 the first letter is @samp{y}, @samp{Y} or @samp{1}, all I/O is
655 unbuffered. This will slow down small sequential reads and writes. If
656 the first letter is @samp{n}, @samp{N} or @samp{0}, I/O is buffered.
657 This is the default.
658
659 @node GFORTRAN_UNBUFFERED_PRECONNECTED
660 @section @env{GFORTRAN_UNBUFFERED_PRECONNECTED}---Do not buffer I/O on preconnected units
661
662 The environment variable named @env{GFORTRAN_UNBUFFERED_PRECONNECTED} controls
663 whether I/O on a preconnected unit (i.e.@: STDOUT or STDERR) is unbuffered. If
664 the first letter is @samp{y}, @samp{Y} or @samp{1}, I/O is unbuffered. This
665 will slow down small sequential reads and writes. If the first letter
666 is @samp{n}, @samp{N} or @samp{0}, I/O is buffered. This is the default.
667
668 @node GFORTRAN_SHOW_LOCUS
669 @section @env{GFORTRAN_SHOW_LOCUS}---Show location for runtime errors
670
671 If the first letter is @samp{y}, @samp{Y} or @samp{1}, filename and
672 line numbers for runtime errors are printed. If the first letter is
673 @samp{n}, @samp{N} or @samp{0}, do not print filename and line numbers
674 for runtime errors. The default is to print the location.
675
676 @node GFORTRAN_OPTIONAL_PLUS
677 @section @env{GFORTRAN_OPTIONAL_PLUS}---Print leading + where permitted
678
679 If the first letter is @samp{y}, @samp{Y} or @samp{1},
680 a plus sign is printed
681 where permitted by the Fortran standard. If the first letter
682 is @samp{n}, @samp{N} or @samp{0}, a plus sign is not printed
683 in most cases. Default is not to print plus signs.
684
685 @node GFORTRAN_LIST_SEPARATOR
686 @section @env{GFORTRAN_LIST_SEPARATOR}---Separator for list output
687
688 This environment variable specifies the separator when writing
689 list-directed output. It may contain any number of spaces and
690 at most one comma. If you specify this on the command line,
691 be sure to quote spaces, as in
692 @smallexample
693 $ GFORTRAN_LIST_SEPARATOR=' , ' ./a.out
694 @end smallexample
695 when @command{a.out} is the compiled Fortran program that you want to run.
696 Default is a single space.
697
698 @node GFORTRAN_CONVERT_UNIT
699 @section @env{GFORTRAN_CONVERT_UNIT}---Set endianness for unformatted I/O
700
701 By setting the @env{GFORTRAN_CONVERT_UNIT} variable, it is possible
702 to change the representation of data for unformatted files.
703 The syntax for the @env{GFORTRAN_CONVERT_UNIT} variable is:
704 @smallexample
705 GFORTRAN_CONVERT_UNIT: mode | mode ';' exception | exception ;
706 mode: 'native' | 'swap' | 'big_endian' | 'little_endian' ;
707 exception: mode ':' unit_list | unit_list ;
708 unit_list: unit_spec | unit_list unit_spec ;
709 unit_spec: INTEGER | INTEGER '-' INTEGER ;
710 @end smallexample
711 The variable consists of an optional default mode, followed by
712 a list of optional exceptions, which are separated by semicolons
713 from the preceding default and each other. Each exception consists
714 of a format and a comma-separated list of units. Valid values for
715 the modes are the same as for the @code{CONVERT} specifier:
716
717 @itemize @w{}
718 @item @code{NATIVE} Use the native format. This is the default.
719 @item @code{SWAP} Swap between little- and big-endian.
720 @item @code{LITTLE_ENDIAN} Use the little-endian format
721 for unformatted files.
722 @item @code{BIG_ENDIAN} Use the big-endian format for unformatted files.
723 @end itemize
724 A missing mode for an exception is taken to mean @code{BIG_ENDIAN}.
725 Examples of values for @env{GFORTRAN_CONVERT_UNIT} are:
726 @itemize @w{}
727 @item @code{'big_endian'} Do all unformatted I/O in big_endian mode.
728 @item @code{'little_endian;native:10-20,25'} Do all unformatted I/O
729 in little_endian mode, except for units 10 to 20 and 25, which are in
730 native format.
731 @item @code{'10-20'} Units 10 to 20 are big-endian, the rest is native.
732 @end itemize
733
734 Setting the environment variables should be done on the command
735 line or via the @command{export}
736 command for @command{sh}-compatible shells and via @command{setenv}
737 for @command{csh}-compatible shells.
738
739 Example for @command{sh}:
740 @smallexample
741 $ gfortran foo.f90
742 $ GFORTRAN_CONVERT_UNIT='big_endian;native:10-20' ./a.out
743 @end smallexample
744
745 Example code for @command{csh}:
746 @smallexample
747 % gfortran foo.f90
748 % setenv GFORTRAN_CONVERT_UNIT 'big_endian;native:10-20'
749 % ./a.out
750 @end smallexample
751
752 Using anything but the native representation for unformatted data
753 carries a significant speed overhead. If speed in this area matters
754 to you, it is best if you use this only for data that needs to be
755 portable.
756
757 @xref{CONVERT specifier}, for an alternative way to specify the
758 data representation for unformatted files. @xref{Runtime Options}, for
759 setting a default data representation for the whole program. The
760 @code{CONVERT} specifier overrides the @option{-fconvert} compile options.
761
762 @emph{Note that the values specified via the GFORTRAN_CONVERT_UNIT
763 environment variable will override the CONVERT specifier in the
764 open statement}. This is to give control over data formats to
765 users who do not have the source code of their program available.
766
767 @node GFORTRAN_ERROR_BACKTRACE
768 @section @env{GFORTRAN_ERROR_BACKTRACE}---Show backtrace on run-time errors
769
770 If the @env{GFORTRAN_ERROR_BACKTRACE} variable is set to @samp{y},
771 @samp{Y} or @samp{1} (only the first letter is relevant) then a
772 backtrace is printed when a serious run-time error occurs. To disable
773 the backtracing, set the variable to @samp{n}, @samp{N}, @samp{0}.
774 Default is to print a backtrace unless the @option{-fno-backtrace}
775 compile option was used.
776
777 @c =====================================================================
778 @c PART II: LANGUAGE REFERENCE
779 @c =====================================================================
780
781 @tex
782 \part{II}{Language Reference}
783 @end tex
784
785 @c ---------------------------------------------------------------------
786 @c Fortran standards status
787 @c ---------------------------------------------------------------------
788
789 @node Fortran standards status
790 @chapter Fortran standards status
791
792 @menu
793 * Fortran 2003 status::
794 * Fortran 2008 status::
795 * Fortran 2018 status::
796 @end menu
797
798 @node Fortran 2003 status
799 @section Fortran 2003 status
800
801 GNU Fortran supports several Fortran 2003 features; an incomplete
802 list can be found below. See also the
803 @uref{https://gcc.gnu.org/wiki/Fortran2003, wiki page} about Fortran 2003.
804
805 @itemize
806 @item Procedure pointers including procedure-pointer components with
807 @code{PASS} attribute.
808
809 @item Procedures which are bound to a derived type (type-bound procedures)
810 including @code{PASS}, @code{PROCEDURE} and @code{GENERIC}, and
811 operators bound to a type.
812
813 @item Abstract interfaces and type extension with the possibility to
814 override type-bound procedures or to have deferred binding.
815
816 @item Polymorphic entities (``@code{CLASS}'') for derived types and unlimited
817 polymorphism (``@code{CLASS(*)}'') -- including @code{SAME_TYPE_AS},
818 @code{EXTENDS_TYPE_OF} and @code{SELECT TYPE} for scalars and arrays and
819 finalization.
820
821 @item Generic interface names, which have the same name as derived types,
822 are now supported. This allows one to write constructor functions. Note
823 that Fortran does not support static constructor functions. For static
824 variables, only default initialization or structure-constructor
825 initialization are available.
826
827 @item The @code{ASSOCIATE} construct.
828
829 @item Interoperability with C including enumerations,
830
831 @item In structure constructors the components with default values may be
832 omitted.
833
834 @item Extensions to the @code{ALLOCATE} statement, allowing for a
835 type-specification with type parameter and for allocation and initialization
836 from a @code{SOURCE=} expression; @code{ALLOCATE} and @code{DEALLOCATE}
837 optionally return an error message string via @code{ERRMSG=}.
838
839 @item Reallocation on assignment: If an intrinsic assignment is
840 used, an allocatable variable on the left-hand side is automatically allocated
841 (if unallocated) or reallocated (if the shape is different). Currently, scalar
842 deferred character length left-hand sides are correctly handled but arrays
843 are not yet fully implemented.
844
845 @item Deferred-length character variables and scalar deferred-length character
846 components of derived types are supported. (Note that array-valued compoents
847 are not yet implemented.)
848
849 @item Transferring of allocations via @code{MOVE_ALLOC}.
850
851 @item The @code{PRIVATE} and @code{PUBLIC} attributes may be given individually
852 to derived-type components.
853
854 @item In pointer assignments, the lower bound may be specified and
855 the remapping of elements is supported.
856
857 @item For pointers an @code{INTENT} may be specified which affect the
858 association status not the value of the pointer target.
859
860 @item Intrinsics @code{command_argument_count}, @code{get_command},
861 @code{get_command_argument}, and @code{get_environment_variable}.
862
863 @item Support for Unicode characters (ISO 10646) and UTF-8, including
864 the @code{SELECTED_CHAR_KIND} and @code{NEW_LINE} intrinsic functions.
865
866 @item Support for binary, octal and hexadecimal (BOZ) constants in the
867 intrinsic functions @code{INT}, @code{REAL}, @code{CMPLX} and @code{DBLE}.
868
869 @item Support for namelist variables with allocatable and pointer
870 attribute and nonconstant length type parameter.
871
872 @item
873 @cindex array, constructors
874 @cindex @code{[...]}
875 Array constructors using square brackets. That is, @code{[...]} rather
876 than @code{(/.../)}. Type-specification for array constructors like
877 @code{(/ some-type :: ... /)}.
878
879 @item Extensions to the specification and initialization expressions,
880 including the support for intrinsics with real and complex arguments.
881
882 @item Support for the asynchronous input/output syntax; however, the
883 data transfer is currently always synchronously performed.
884
885 @item
886 @cindex @code{FLUSH} statement
887 @cindex statement, @code{FLUSH}
888 @code{FLUSH} statement.
889
890 @item
891 @cindex @code{IOMSG=} specifier
892 @code{IOMSG=} specifier for I/O statements.
893
894 @item
895 @cindex @code{ENUM} statement
896 @cindex @code{ENUMERATOR} statement
897 @cindex statement, @code{ENUM}
898 @cindex statement, @code{ENUMERATOR}
899 @opindex @code{fshort-enums}
900 Support for the declaration of enumeration constants via the
901 @code{ENUM} and @code{ENUMERATOR} statements. Interoperability with
902 @command{gcc} is guaranteed also for the case where the
903 @command{-fshort-enums} command line option is given.
904
905 @item
906 @cindex TR 15581
907 TR 15581:
908 @itemize
909 @item
910 @cindex @code{ALLOCATABLE} dummy arguments
911 @code{ALLOCATABLE} dummy arguments.
912 @item
913 @cindex @code{ALLOCATABLE} function results
914 @code{ALLOCATABLE} function results
915 @item
916 @cindex @code{ALLOCATABLE} components of derived types
917 @code{ALLOCATABLE} components of derived types
918 @end itemize
919
920 @item
921 @cindex @code{STREAM} I/O
922 @cindex @code{ACCESS='STREAM'} I/O
923 The @code{OPEN} statement supports the @code{ACCESS='STREAM'} specifier,
924 allowing I/O without any record structure.
925
926 @item
927 Namelist input/output for internal files.
928
929 @item Minor I/O features: Rounding during formatted output, using of
930 a decimal comma instead of a decimal point, setting whether a plus sign
931 should appear for positive numbers. On systems where @code{strtod} honours
932 the rounding mode, the rounding mode is also supported for input.
933
934 @item
935 @cindex @code{PROTECTED} statement
936 @cindex statement, @code{PROTECTED}
937 The @code{PROTECTED} statement and attribute.
938
939 @item
940 @cindex @code{VALUE} statement
941 @cindex statement, @code{VALUE}
942 The @code{VALUE} statement and attribute.
943
944 @item
945 @cindex @code{VOLATILE} statement
946 @cindex statement, @code{VOLATILE}
947 The @code{VOLATILE} statement and attribute.
948
949 @item
950 @cindex @code{IMPORT} statement
951 @cindex statement, @code{IMPORT}
952 The @code{IMPORT} statement, allowing to import
953 host-associated derived types.
954
955 @item The intrinsic modules @code{ISO_FORTRAN_ENVIRONMENT} is supported,
956 which contains parameters of the I/O units, storage sizes. Additionally,
957 procedures for C interoperability are available in the @code{ISO_C_BINDING}
958 module.
959
960 @item
961 @cindex @code{USE, INTRINSIC} statement
962 @cindex statement, @code{USE, INTRINSIC}
963 @cindex @code{ISO_FORTRAN_ENV} statement
964 @cindex statement, @code{ISO_FORTRAN_ENV}
965 @code{USE} statement with @code{INTRINSIC} and @code{NON_INTRINSIC}
966 attribute; supported intrinsic modules: @code{ISO_FORTRAN_ENV},
967 @code{ISO_C_BINDING}, @code{OMP_LIB} and @code{OMP_LIB_KINDS},
968 and @code{OPENACC}.
969
970 @item
971 Renaming of operators in the @code{USE} statement.
972
973 @end itemize
974
975
976 @node Fortran 2008 status
977 @section Fortran 2008 status
978
979 The latest version of the Fortran standard is ISO/IEC 1539-1:2010, informally
980 known as Fortran 2008. The official version is available from International
981 Organization for Standardization (ISO) or its national member organizations.
982 The the final draft (FDIS) can be downloaded free of charge from
983 @url{http://www.nag.co.uk/@/sc22wg5/@/links.html}. Fortran is developed by the
984 Working Group 5 of Sub-Committee 22 of the Joint Technical Committee 1 of the
985 International Organization for Standardization and the International
986 Electrotechnical Commission (IEC). This group is known as
987 @uref{http://www.nag.co.uk/sc22wg5/, WG5}.
988
989 The GNU Fortran compiler supports several of the new features of Fortran 2008;
990 the @uref{https://gcc.gnu.org/wiki/Fortran2008Status, wiki} has some information
991 about the current Fortran 2008 implementation status. In particular, the
992 following is implemented.
993
994 @itemize
995 @item The @option{-std=f2008} option and support for the file extensions
996 @file{.f08} and @file{.F08}.
997
998 @item The @code{OPEN} statement now supports the @code{NEWUNIT=} option,
999 which returns a unique file unit, thus preventing inadvertent use of the
1000 same unit in different parts of the program.
1001
1002 @item The @code{g0} format descriptor and unlimited format items.
1003
1004 @item The mathematical intrinsics @code{ASINH}, @code{ACOSH}, @code{ATANH},
1005 @code{ERF}, @code{ERFC}, @code{GAMMA}, @code{LOG_GAMMA}, @code{BESSEL_J0},
1006 @code{BESSEL_J1}, @code{BESSEL_JN}, @code{BESSEL_Y0}, @code{BESSEL_Y1},
1007 @code{BESSEL_YN}, @code{HYPOT}, @code{NORM2}, and @code{ERFC_SCALED}.
1008
1009 @item Using complex arguments with @code{TAN}, @code{SINH}, @code{COSH},
1010 @code{TANH}, @code{ASIN}, @code{ACOS}, and @code{ATAN} is now possible;
1011 @code{ATAN}(@var{Y},@var{X}) is now an alias for @code{ATAN2}(@var{Y},@var{X}).
1012
1013 @item Support of the @code{PARITY} intrinsic functions.
1014
1015 @item The following bit intrinsics: @code{LEADZ} and @code{TRAILZ} for
1016 counting the number of leading and trailing zero bits, @code{POPCNT} and
1017 @code{POPPAR} for counting the number of one bits and returning the parity;
1018 @code{BGE}, @code{BGT}, @code{BLE}, and @code{BLT} for bitwise comparisons;
1019 @code{DSHIFTL} and @code{DSHIFTR} for combined left and right shifts,
1020 @code{MASKL} and @code{MASKR} for simple left and right justified masks,
1021 @code{MERGE_BITS} for a bitwise merge using a mask, @code{SHIFTA},
1022 @code{SHIFTL} and @code{SHIFTR} for shift operations, and the
1023 transformational bit intrinsics @code{IALL}, @code{IANY} and @code{IPARITY}.
1024
1025 @item Support of the @code{EXECUTE_COMMAND_LINE} intrinsic subroutine.
1026
1027 @item Support for the @code{STORAGE_SIZE} intrinsic inquiry function.
1028
1029 @item The @code{INT@{8,16,32@}} and @code{REAL@{32,64,128@}} kind type
1030 parameters and the array-valued named constants @code{INTEGER_KINDS},
1031 @code{LOGICAL_KINDS}, @code{REAL_KINDS} and @code{CHARACTER_KINDS} of
1032 the intrinsic module @code{ISO_FORTRAN_ENV}.
1033
1034 @item The module procedures @code{C_SIZEOF} of the intrinsic module
1035 @code{ISO_C_BINDINGS} and @code{COMPILER_VERSION} and @code{COMPILER_OPTIONS}
1036 of @code{ISO_FORTRAN_ENV}.
1037
1038 @item Coarray support for serial programs with @option{-fcoarray=single} flag
1039 and experimental support for multiple images with the @option{-fcoarray=lib}
1040 flag.
1041
1042 @item Submodules are supported. It should noted that @code{MODULEs} do not
1043 produce the smod file needed by the descendent @code{SUBMODULEs} unless they
1044 contain at least one @code{MODULE PROCEDURE} interface. The reason for this is
1045 that @code{SUBMODULEs} are useless without @code{MODULE PROCEDUREs}. See
1046 http://j3-fortran.org/doc/meeting/207/15-209.txt for a discussion and a draft
1047 interpretation. Adopting this interpretation has the advantage that code that
1048 does not use submodules does not generate smod files.
1049
1050 @item The @code{DO CONCURRENT} construct is supported.
1051
1052 @item The @code{BLOCK} construct is supported.
1053
1054 @item The @code{STOP} and the new @code{ERROR STOP} statements now
1055 support all constant expressions. Both show the signals which were signaling
1056 at termination.
1057
1058 @item Support for the @code{CONTIGUOUS} attribute.
1059
1060 @item Support for @code{ALLOCATE} with @code{MOLD}.
1061
1062 @item Support for the @code{IMPURE} attribute for procedures, which
1063 allows for @code{ELEMENTAL} procedures without the restrictions of
1064 @code{PURE}.
1065
1066 @item Null pointers (including @code{NULL()}) and not-allocated variables
1067 can be used as actual argument to optional non-pointer, non-allocatable
1068 dummy arguments, denoting an absent argument.
1069
1070 @item Non-pointer variables with @code{TARGET} attribute can be used as
1071 actual argument to @code{POINTER} dummies with @code{INTENT(IN)}.
1072
1073 @item Pointers including procedure pointers and those in a derived
1074 type (pointer components) can now be initialized by a target instead
1075 of only by @code{NULL}.
1076
1077 @item The @code{EXIT} statement (with construct-name) can be now be
1078 used to leave not only the @code{DO} but also the @code{ASSOCIATE},
1079 @code{BLOCK}, @code{IF}, @code{SELECT CASE} and @code{SELECT TYPE}
1080 constructs.
1081
1082 @item Internal procedures can now be used as actual argument.
1083
1084 @item Minor features: obsolesce diagnostics for @code{ENTRY} with
1085 @option{-std=f2008}; a line may start with a semicolon; for internal
1086 and module procedures @code{END} can be used instead of
1087 @code{END SUBROUTINE} and @code{END FUNCTION}; @code{SELECTED_REAL_KIND}
1088 now also takes a @code{RADIX} argument; intrinsic types are supported
1089 for @code{TYPE}(@var{intrinsic-type-spec}); multiple type-bound procedures
1090 can be declared in a single @code{PROCEDURE} statement; implied-shape
1091 arrays are supported for named constants (@code{PARAMETER}).
1092 @end itemize
1093
1094
1095
1096 @node Fortran 2018 status
1097 @section Status of Fortran 2018 support
1098
1099 So far very little work has been done to support Fortran 2018.
1100
1101 @itemize
1102 @item ERROR STOP in a PURE procedure
1103 An @code{ERROR STOP} statement is permitted in a @code{PURE}
1104 procedure.
1105
1106 @item IMPLICIT NONE with a spec-list
1107 Support the @code{IMPLICIT NONE} statement with an
1108 @code{implicit-none-spec-list}.
1109
1110 @item Behavior of INQUIRE with the RECL= specifier
1111
1112 The behavior of the @code{INQUIRE} statement with the @code{RECL=}
1113 specifier now conforms to Fortran 2018.
1114
1115 @end itemize
1116
1117
1118 @subsection TS 29113 Status (Further Interoperability with C)
1119
1120 GNU Fortran supports some of the new features of the Technical
1121 Specification (TS) 29113 on Further Interoperability of Fortran with C.
1122 The @uref{https://gcc.gnu.org/wiki/TS29113Status, wiki} has some information
1123 about the current TS 29113 implementation status. In particular, the
1124 following is implemented.
1125
1126 See also @ref{Further Interoperability of Fortran with C}.
1127
1128 @itemize
1129 @item The @code{OPTIONAL} attribute is allowed for dummy arguments
1130 of @code{BIND(C) procedures.}
1131
1132 @item The @code{RANK} intrinsic is supported.
1133
1134 @item GNU Fortran's implementation for variables with @code{ASYNCHRONOUS}
1135 attribute is compatible with TS 29113.
1136
1137 @item Assumed types (@code{TYPE(*)}).
1138
1139 @item Assumed-rank (@code{DIMENSION(..)}). However, the array descriptor
1140 of the TS is not yet supported.
1141 @end itemize
1142
1143
1144
1145 @subsection TS 18508 Status (Additional Parallel Features)
1146
1147 GNU Fortran supports the following new features of the Technical
1148 Specification 18508 on Additional Parallel Features in Fortran:
1149
1150 @itemize
1151 @item The new atomic ADD, CAS, FETCH and ADD/OR/XOR, OR and XOR intrinsics.
1152
1153 @item The @code{CO_MIN} and @code{CO_MAX} and @code{SUM} reduction intrinsics.
1154 And the @code{CO_BROADCAST} and @code{CO_REDUCE} intrinsic, except that those
1155 do not support polymorphic types or types with allocatable, pointer or
1156 polymorphic components.
1157
1158 @item Events (@code{EVENT POST}, @code{EVENT WAIT}, @code{EVENT_QUERY})
1159
1160 @item Failed images (@code{FAIL IMAGE}, @code{IMAGE_STATUS},
1161 @code{FAILED_IMAGES}, @code{STOPPED_IMAGES})
1162
1163 @end itemize
1164
1165
1166 @c ---------------------------------------------------------------------
1167 @c Compiler Characteristics
1168 @c ---------------------------------------------------------------------
1169
1170 @node Compiler Characteristics
1171 @chapter Compiler Characteristics
1172
1173 This chapter describes certain characteristics of the GNU Fortran
1174 compiler, that are not specified by the Fortran standard, but which
1175 might in some way or another become visible to the programmer.
1176
1177 @menu
1178 * KIND Type Parameters::
1179 * Internal representation of LOGICAL variables::
1180 * Evaluation of logical expressions::
1181 * Thread-safety of the runtime library::
1182 * Data consistency and durability::
1183 * Files opened without an explicit ACTION= specifier::
1184 * File operations on symbolic links::
1185 * File format of unformatted sequential files::
1186 @end menu
1187
1188
1189 @node KIND Type Parameters
1190 @section KIND Type Parameters
1191 @cindex kind
1192
1193 The @code{KIND} type parameters supported by GNU Fortran for the primitive
1194 data types are:
1195
1196 @table @code
1197
1198 @item INTEGER
1199 1, 2, 4, 8*, 16*, default: 4**
1200
1201 @item LOGICAL
1202 1, 2, 4, 8*, 16*, default: 4**
1203
1204 @item REAL
1205 4, 8, 10*, 16*, default: 4***
1206
1207 @item COMPLEX
1208 4, 8, 10*, 16*, default: 4***
1209
1210 @item DOUBLE PRECISION
1211 4, 8, 10*, 16*, default: 8***
1212
1213 @item CHARACTER
1214 1, 4, default: 1
1215
1216 @end table
1217
1218 @noindent
1219 * not available on all systems @*
1220 ** unless @option{-fdefault-integer-8} is used @*
1221 *** unless @option{-fdefault-real-8} is used (see @ref{Fortran Dialect Options})
1222
1223 @noindent
1224 The @code{KIND} value matches the storage size in bytes, except for
1225 @code{COMPLEX} where the storage size is twice as much (or both real and
1226 imaginary part are a real value of the given size). It is recommended to use
1227 the @ref{SELECTED_CHAR_KIND}, @ref{SELECTED_INT_KIND} and
1228 @ref{SELECTED_REAL_KIND} intrinsics or the @code{INT8}, @code{INT16},
1229 @code{INT32}, @code{INT64}, @code{REAL32}, @code{REAL64}, and @code{REAL128}
1230 parameters of the @code{ISO_FORTRAN_ENV} module instead of the concrete values.
1231 The available kind parameters can be found in the constant arrays
1232 @code{CHARACTER_KINDS}, @code{INTEGER_KINDS}, @code{LOGICAL_KINDS} and
1233 @code{REAL_KINDS} in the @ref{ISO_FORTRAN_ENV} module. For C interoperability,
1234 the kind parameters of the @ref{ISO_C_BINDING} module should be used.
1235
1236
1237 @node Internal representation of LOGICAL variables
1238 @section Internal representation of LOGICAL variables
1239 @cindex logical, variable representation
1240
1241 The Fortran standard does not specify how variables of @code{LOGICAL}
1242 type are represented, beyond requiring that @code{LOGICAL} variables
1243 of default kind have the same storage size as default @code{INTEGER}
1244 and @code{REAL} variables. The GNU Fortran internal representation is
1245 as follows.
1246
1247 A @code{LOGICAL(KIND=N)} variable is represented as an
1248 @code{INTEGER(KIND=N)} variable, however, with only two permissible
1249 values: @code{1} for @code{.TRUE.} and @code{0} for
1250 @code{.FALSE.}. Any other integer value results in undefined behavior.
1251
1252 See also @ref{Argument passing conventions} and @ref{Interoperability with C}.
1253
1254
1255 @node Evaluation of logical expressions
1256 @section Evaluation of logical expressions
1257
1258 The Fortran standard does not require the compiler to evaluate all parts of an
1259 expression, if they do not contribute to the final result. For logical
1260 expressions with @code{.AND.} or @code{.OR.} operators, in particular, GNU
1261 Fortran will optimize out function calls (even to impure functions) if the
1262 result of the expression can be established without them. However, since not
1263 all compilers do that, and such an optimization can potentially modify the
1264 program flow and subsequent results, GNU Fortran throws warnings for such
1265 situations with the @option{-Wfunction-elimination} flag.
1266
1267
1268 @node Thread-safety of the runtime library
1269 @section Thread-safety of the runtime library
1270 @cindex thread-safety, threads
1271
1272 GNU Fortran can be used in programs with multiple threads, e.g.@: by
1273 using OpenMP, by calling OS thread handling functions via the
1274 @code{ISO_C_BINDING} facility, or by GNU Fortran compiled library code
1275 being called from a multi-threaded program.
1276
1277 The GNU Fortran runtime library, (@code{libgfortran}), supports being
1278 called concurrently from multiple threads with the following
1279 exceptions.
1280
1281 During library initialization, the C @code{getenv} function is used,
1282 which need not be thread-safe. Similarly, the @code{getenv}
1283 function is used to implement the @code{GET_ENVIRONMENT_VARIABLE} and
1284 @code{GETENV} intrinsics. It is the responsibility of the user to
1285 ensure that the environment is not being updated concurrently when any
1286 of these actions are taking place.
1287
1288 The @code{EXECUTE_COMMAND_LINE} and @code{SYSTEM} intrinsics are
1289 implemented with the @code{system} function, which need not be
1290 thread-safe. It is the responsibility of the user to ensure that
1291 @code{system} is not called concurrently.
1292
1293 For platforms not supporting thread-safe POSIX functions, further
1294 functionality might not be thread-safe. For details, please consult
1295 the documentation for your operating system.
1296
1297 The GNU Fortran runtime library uses various C library functions that
1298 depend on the locale, such as @code{strtod} and @code{snprintf}. In
1299 order to work correctly in locale-aware programs that set the locale
1300 using @code{setlocale}, the locale is reset to the default ``C''
1301 locale while executing a formatted @code{READ} or @code{WRITE}
1302 statement. On targets supporting the POSIX 2008 per-thread locale
1303 functions (e.g. @code{newlocale}, @code{uselocale},
1304 @code{freelocale}), these are used and thus the global locale set
1305 using @code{setlocale} or the per-thread locales in other threads are
1306 not affected. However, on targets lacking this functionality, the
1307 global LC_NUMERIC locale is set to ``C'' during the formatted I/O.
1308 Thus, on such targets it's not safe to call @code{setlocale}
1309 concurrently from another thread while a Fortran formatted I/O
1310 operation is in progress. Also, other threads doing something
1311 dependent on the LC_NUMERIC locale might not work correctly if a
1312 formatted I/O operation is in progress in another thread.
1313
1314 @node Data consistency and durability
1315 @section Data consistency and durability
1316 @cindex consistency, durability
1317
1318 This section contains a brief overview of data and metadata
1319 consistency and durability issues when doing I/O.
1320
1321 With respect to durability, GNU Fortran makes no effort to ensure that
1322 data is committed to stable storage. If this is required, the GNU
1323 Fortran programmer can use the intrinsic @code{FNUM} to retrieve the
1324 low level file descriptor corresponding to an open Fortran unit. Then,
1325 using e.g. the @code{ISO_C_BINDING} feature, one can call the
1326 underlying system call to flush dirty data to stable storage, such as
1327 @code{fsync} on POSIX, @code{_commit} on MingW, or @code{fcntl(fd,
1328 F_FULLSYNC, 0)} on Mac OS X. The following example shows how to call
1329 fsync:
1330
1331 @smallexample
1332 ! Declare the interface for POSIX fsync function
1333 interface
1334 function fsync (fd) bind(c,name="fsync")
1335 use iso_c_binding, only: c_int
1336 integer(c_int), value :: fd
1337 integer(c_int) :: fsync
1338 end function fsync
1339 end interface
1340
1341 ! Variable declaration
1342 integer :: ret
1343
1344 ! Opening unit 10
1345 open (10,file="foo")
1346
1347 ! ...
1348 ! Perform I/O on unit 10
1349 ! ...
1350
1351 ! Flush and sync
1352 flush(10)
1353 ret = fsync(fnum(10))
1354
1355 ! Handle possible error
1356 if (ret /= 0) stop "Error calling FSYNC"
1357 @end smallexample
1358
1359 With respect to consistency, for regular files GNU Fortran uses
1360 buffered I/O in order to improve performance. This buffer is flushed
1361 automatically when full and in some other situations, e.g. when
1362 closing a unit. It can also be explicitly flushed with the
1363 @code{FLUSH} statement. Also, the buffering can be turned off with the
1364 @code{GFORTRAN_UNBUFFERED_ALL} and
1365 @code{GFORTRAN_UNBUFFERED_PRECONNECTED} environment variables. Special
1366 files, such as terminals and pipes, are always unbuffered. Sometimes,
1367 however, further things may need to be done in order to allow other
1368 processes to see data that GNU Fortran has written, as follows.
1369
1370 The Windows platform supports a relaxed metadata consistency model,
1371 where file metadata is written to the directory lazily. This means
1372 that, for instance, the @code{dir} command can show a stale size for a
1373 file. One can force a directory metadata update by closing the unit,
1374 or by calling @code{_commit} on the file descriptor. Note, though,
1375 that @code{_commit} will force all dirty data to stable storage, which
1376 is often a very slow operation.
1377
1378 The Network File System (NFS) implements a relaxed consistency model
1379 called open-to-close consistency. Closing a file forces dirty data and
1380 metadata to be flushed to the server, and opening a file forces the
1381 client to contact the server in order to revalidate cached
1382 data. @code{fsync} will also force a flush of dirty data and metadata
1383 to the server. Similar to @code{open} and @code{close}, acquiring and
1384 releasing @code{fcntl} file locks, if the server supports them, will
1385 also force cache validation and flushing dirty data and metadata.
1386
1387
1388 @node Files opened without an explicit ACTION= specifier
1389 @section Files opened without an explicit ACTION= specifier
1390 @cindex open, action
1391
1392 The Fortran standard says that if an @code{OPEN} statement is executed
1393 without an explicit @code{ACTION=} specifier, the default value is
1394 processor dependent. GNU Fortran behaves as follows:
1395
1396 @enumerate
1397 @item Attempt to open the file with @code{ACTION='READWRITE'}
1398 @item If that fails, try to open with @code{ACTION='READ'}
1399 @item If that fails, try to open with @code{ACTION='WRITE'}
1400 @item If that fails, generate an error
1401 @end enumerate
1402
1403
1404 @node File operations on symbolic links
1405 @section File operations on symbolic links
1406 @cindex file, symbolic link
1407
1408 This section documents the behavior of GNU Fortran for file operations on
1409 symbolic links, on systems that support them.
1410
1411 @itemize
1412
1413 @item Results of INQUIRE statements of the ``inquire by file'' form will
1414 relate to the target of the symbolic link. For example,
1415 @code{INQUIRE(FILE="foo",EXIST=ex)} will set @var{ex} to @var{.true.} if
1416 @var{foo} is a symbolic link pointing to an existing file, and @var{.false.}
1417 if @var{foo} points to an non-existing file (``dangling'' symbolic link).
1418
1419 @item Using the @code{OPEN} statement with a @code{STATUS="NEW"} specifier
1420 on a symbolic link will result in an error condition, whether the symbolic
1421 link points to an existing target or is dangling.
1422
1423 @item If a symbolic link was connected, using the @code{CLOSE} statement
1424 with a @code{STATUS="DELETE"} specifier will cause the symbolic link itself
1425 to be deleted, not its target.
1426
1427 @end itemize
1428
1429 @node File format of unformatted sequential files
1430 @section File format of unformatted sequential files
1431 @cindex file, unformatted sequential
1432 @cindex unformatted sequential
1433 @cindex sequential, unformatted
1434 @cindex record marker
1435 @cindex subrecord
1436
1437 Unformatted sequential files are stored as logical records using
1438 record markers. Each logical record consists of one of more
1439 subrecords.
1440
1441 Each subrecord consists of a leading record marker, the data written
1442 by the user program, and a trailing record marker. The record markers
1443 are four-byte integers by default, and eight-byte integers if the
1444 @option{-fmax-subrecord-length=8} option (which exists for backwards
1445 compability only) is in effect.
1446
1447 The representation of the record markers is that of unformatted files
1448 given with the @option{-fconvert} option, the @xref{CONVERT specifier}
1449 on the open statement or the @xref{GFORTRAN_CONVERT_UNIT} environment
1450 variable.
1451
1452 The maximum number of bytes of user data in a subrecord is 2147483639
1453 (2 GiB - 9) for a four-byte record marker. This limit can be lowered
1454 with the @option{-fmax-subrecord-length} option, altough this is
1455 rarely useful. If the length of a logical record exceeds this limit,
1456 the data is distributed among several subrecords.
1457
1458 The absolute of the number stored in the record markers is the number
1459 of bytes of user data in the corresponding subrecord. If the leading
1460 record marker of a subrecord contains a negative number, another
1461 subrecord follows the current one. If the trailing record marker
1462 contains a negative number, then there is a preceding subrecord.
1463
1464 In the most simple case, with only one subrecord per logical record,
1465 both record markers contain the number of bytes of user data in the
1466 record,
1467
1468 The format for unformatted sequential data can be duplicated using
1469 unformatted stream, as shown in the example program for an unformatted
1470 record containing a single subrecord:
1471
1472 @smallexample
1473 program main
1474 use iso_fortran_env, only: int32
1475 implicit none
1476 integer(int32) :: i
1477 real, dimension(10) :: a, b
1478 call random_number(a)
1479 open (10,file='test.dat',form='unformatted',access='stream')
1480 inquire (iolength=i) a
1481 write (10) i, a, i
1482 close (10)
1483 open (10,file='test.dat',form='unformatted')
1484 read (10) b
1485 if (all (a == b)) print *,'success!'
1486 end program main
1487 @end smallexample
1488
1489 @c ---------------------------------------------------------------------
1490 @c Extensions
1491 @c ---------------------------------------------------------------------
1492
1493 @c Maybe this chapter should be merged with the 'Standards' section,
1494 @c whenever that is written :-)
1495
1496 @node Extensions
1497 @chapter Extensions
1498 @cindex extensions
1499
1500 The two sections below detail the extensions to standard Fortran that are
1501 implemented in GNU Fortran, as well as some of the popular or
1502 historically important extensions that are not (or not yet) implemented.
1503 For the latter case, we explain the alternatives available to GNU Fortran
1504 users, including replacement by standard-conforming code or GNU
1505 extensions.
1506
1507 @menu
1508 * Extensions implemented in GNU Fortran::
1509 * Extensions not implemented in GNU Fortran::
1510 @end menu
1511
1512
1513 @node Extensions implemented in GNU Fortran
1514 @section Extensions implemented in GNU Fortran
1515 @cindex extensions, implemented
1516
1517 GNU Fortran implements a number of extensions over standard Fortran.
1518 This chapter contains information on their syntax and meaning. There
1519 are currently two categories of GNU Fortran extensions, those that
1520 provide functionality beyond that provided by any standard, and those
1521 that are supported by GNU Fortran purely for backward compatibility
1522 with legacy compilers. By default, @option{-std=gnu} allows the
1523 compiler to accept both types of extensions, but to warn about the use
1524 of the latter. Specifying either @option{-std=f95},
1525 @option{-std=f2003}, @option{-std=f2008}, or @option{-std=f2018}
1526 disables both types of extensions, and @option{-std=legacy} allows
1527 both without warning. The special compile flag @option{-fdec} enables
1528 additional compatibility extensions along with those enabled by
1529 @option{-std=legacy}.
1530
1531 @menu
1532 * Old-style kind specifications::
1533 * Old-style variable initialization::
1534 * Extensions to namelist::
1535 * X format descriptor without count field::
1536 * Commas in FORMAT specifications::
1537 * Missing period in FORMAT specifications::
1538 * I/O item lists::
1539 * @code{Q} exponent-letter::
1540 * BOZ literal constants::
1541 * Real array indices::
1542 * Unary operators::
1543 * Implicitly convert LOGICAL and INTEGER values::
1544 * Hollerith constants support::
1545 * Cray pointers::
1546 * CONVERT specifier::
1547 * OpenMP::
1548 * OpenACC::
1549 * Argument list functions::
1550 * Read/Write after EOF marker::
1551 * STRUCTURE and RECORD::
1552 * UNION and MAP::
1553 * Type variants for integer intrinsics::
1554 * AUTOMATIC and STATIC attributes::
1555 * Extended math intrinsics::
1556 * Form feed as whitespace::
1557 * TYPE as an alias for PRINT::
1558 * %LOC as an rvalue::
1559 * .XOR. operator::
1560 * Bitwise logical operators::
1561 * Extended I/O specifiers::
1562 * Legacy PARAMETER statements::
1563 * Default exponents::
1564 @end menu
1565
1566 @node Old-style kind specifications
1567 @subsection Old-style kind specifications
1568 @cindex kind, old-style
1569
1570 GNU Fortran allows old-style kind specifications in declarations. These
1571 look like:
1572 @smallexample
1573 TYPESPEC*size x,y,z
1574 @end smallexample
1575 @noindent
1576 where @code{TYPESPEC} is a basic type (@code{INTEGER}, @code{REAL},
1577 etc.), and where @code{size} is a byte count corresponding to the
1578 storage size of a valid kind for that type. (For @code{COMPLEX}
1579 variables, @code{size} is the total size of the real and imaginary
1580 parts.) The statement then declares @code{x}, @code{y} and @code{z} to
1581 be of type @code{TYPESPEC} with the appropriate kind. This is
1582 equivalent to the standard-conforming declaration
1583 @smallexample
1584 TYPESPEC(k) x,y,z
1585 @end smallexample
1586 @noindent
1587 where @code{k} is the kind parameter suitable for the intended precision. As
1588 kind parameters are implementation-dependent, use the @code{KIND},
1589 @code{SELECTED_INT_KIND} and @code{SELECTED_REAL_KIND} intrinsics to retrieve
1590 the correct value, for instance @code{REAL*8 x} can be replaced by:
1591 @smallexample
1592 INTEGER, PARAMETER :: dbl = KIND(1.0d0)
1593 REAL(KIND=dbl) :: x
1594 @end smallexample
1595
1596 @node Old-style variable initialization
1597 @subsection Old-style variable initialization
1598
1599 GNU Fortran allows old-style initialization of variables of the
1600 form:
1601 @smallexample
1602 INTEGER i/1/,j/2/
1603 REAL x(2,2) /3*0.,1./
1604 @end smallexample
1605 The syntax for the initializers is as for the @code{DATA} statement, but
1606 unlike in a @code{DATA} statement, an initializer only applies to the
1607 variable immediately preceding the initialization. In other words,
1608 something like @code{INTEGER I,J/2,3/} is not valid. This style of
1609 initialization is only allowed in declarations without double colons
1610 (@code{::}); the double colons were introduced in Fortran 90, which also
1611 introduced a standard syntax for initializing variables in type
1612 declarations.
1613
1614 Examples of standard-conforming code equivalent to the above example
1615 are:
1616 @smallexample
1617 ! Fortran 90
1618 INTEGER :: i = 1, j = 2
1619 REAL :: x(2,2) = RESHAPE((/0.,0.,0.,1./),SHAPE(x))
1620 ! Fortran 77
1621 INTEGER i, j
1622 REAL x(2,2)
1623 DATA i/1/, j/2/, x/3*0.,1./
1624 @end smallexample
1625
1626 Note that variables which are explicitly initialized in declarations
1627 or in @code{DATA} statements automatically acquire the @code{SAVE}
1628 attribute.
1629
1630 @node Extensions to namelist
1631 @subsection Extensions to namelist
1632 @cindex Namelist
1633
1634 GNU Fortran fully supports the Fortran 95 standard for namelist I/O
1635 including array qualifiers, substrings and fully qualified derived types.
1636 The output from a namelist write is compatible with namelist read. The
1637 output has all names in upper case and indentation to column 1 after the
1638 namelist name. Two extensions are permitted:
1639
1640 Old-style use of @samp{$} instead of @samp{&}
1641 @smallexample
1642 $MYNML
1643 X(:)%Y(2) = 1.0 2.0 3.0
1644 CH(1:4) = "abcd"
1645 $END
1646 @end smallexample
1647
1648 It should be noted that the default terminator is @samp{/} rather than
1649 @samp{&END}.
1650
1651 Querying of the namelist when inputting from stdin. After at least
1652 one space, entering @samp{?} sends to stdout the namelist name and the names of
1653 the variables in the namelist:
1654 @smallexample
1655 ?
1656
1657 &mynml
1658 x
1659 x%y
1660 ch
1661 &end
1662 @end smallexample
1663
1664 Entering @samp{=?} outputs the namelist to stdout, as if
1665 @code{WRITE(*,NML = mynml)} had been called:
1666 @smallexample
1667 =?
1668
1669 &MYNML
1670 X(1)%Y= 0.000000 , 1.000000 , 0.000000 ,
1671 X(2)%Y= 0.000000 , 2.000000 , 0.000000 ,
1672 X(3)%Y= 0.000000 , 3.000000 , 0.000000 ,
1673 CH=abcd, /
1674 @end smallexample
1675
1676 To aid this dialog, when input is from stdin, errors send their
1677 messages to stderr and execution continues, even if @code{IOSTAT} is set.
1678
1679 @code{PRINT} namelist is permitted. This causes an error if
1680 @option{-std=f95} is used.
1681 @smallexample
1682 PROGRAM test_print
1683 REAL, dimension (4) :: x = (/1.0, 2.0, 3.0, 4.0/)
1684 NAMELIST /mynml/ x
1685 PRINT mynml
1686 END PROGRAM test_print
1687 @end smallexample
1688
1689 Expanded namelist reads are permitted. This causes an error if
1690 @option{-std=f95} is used. In the following example, the first element
1691 of the array will be given the value 0.00 and the two succeeding
1692 elements will be given the values 1.00 and 2.00.
1693 @smallexample
1694 &MYNML
1695 X(1,1) = 0.00 , 1.00 , 2.00
1696 /
1697 @end smallexample
1698
1699 When writing a namelist, if no @code{DELIM=} is specified, by default a
1700 double quote is used to delimit character strings. If -std=F95, F2003,
1701 or F2008, etc, the delim status is set to 'none'. Defaulting to
1702 quotes ensures that namelists with character strings can be subsequently
1703 read back in accurately.
1704
1705 @node X format descriptor without count field
1706 @subsection @code{X} format descriptor without count field
1707
1708 To support legacy codes, GNU Fortran permits the count field of the
1709 @code{X} edit descriptor in @code{FORMAT} statements to be omitted.
1710 When omitted, the count is implicitly assumed to be one.
1711
1712 @smallexample
1713 PRINT 10, 2, 3
1714 10 FORMAT (I1, X, I1)
1715 @end smallexample
1716
1717 @node Commas in FORMAT specifications
1718 @subsection Commas in @code{FORMAT} specifications
1719
1720 To support legacy codes, GNU Fortran allows the comma separator
1721 to be omitted immediately before and after character string edit
1722 descriptors in @code{FORMAT} statements.
1723
1724 @smallexample
1725 PRINT 10, 2, 3
1726 10 FORMAT ('FOO='I1' BAR='I2)
1727 @end smallexample
1728
1729
1730 @node Missing period in FORMAT specifications
1731 @subsection Missing period in @code{FORMAT} specifications
1732
1733 To support legacy codes, GNU Fortran allows missing periods in format
1734 specifications if and only if @option{-std=legacy} is given on the
1735 command line. This is considered non-conforming code and is
1736 discouraged.
1737
1738 @smallexample
1739 REAL :: value
1740 READ(*,10) value
1741 10 FORMAT ('F4')
1742 @end smallexample
1743
1744 @node I/O item lists
1745 @subsection I/O item lists
1746 @cindex I/O item lists
1747
1748 To support legacy codes, GNU Fortran allows the input item list
1749 of the @code{READ} statement, and the output item lists of the
1750 @code{WRITE} and @code{PRINT} statements, to start with a comma.
1751
1752 @node @code{Q} exponent-letter
1753 @subsection @code{Q} exponent-letter
1754 @cindex @code{Q} exponent-letter
1755
1756 GNU Fortran accepts real literal constants with an exponent-letter
1757 of @code{Q}, for example, @code{1.23Q45}. The constant is interpreted
1758 as a @code{REAL(16)} entity on targets that support this type. If
1759 the target does not support @code{REAL(16)} but has a @code{REAL(10)}
1760 type, then the real-literal-constant will be interpreted as a
1761 @code{REAL(10)} entity. In the absence of @code{REAL(16)} and
1762 @code{REAL(10)}, an error will occur.
1763
1764 @node BOZ literal constants
1765 @subsection BOZ literal constants
1766 @cindex BOZ literal constants
1767
1768 Besides decimal constants, Fortran also supports binary (@code{b}),
1769 octal (@code{o}) and hexadecimal (@code{z}) integer constants. The
1770 syntax is: @samp{prefix quote digits quote}, were the prefix is
1771 either @code{b}, @code{o} or @code{z}, quote is either @code{'} or
1772 @code{"} and the digits are for binary @code{0} or @code{1}, for
1773 octal between @code{0} and @code{7}, and for hexadecimal between
1774 @code{0} and @code{F}. (Example: @code{b'01011101'}.)
1775
1776 Up to Fortran 95, BOZ literals were only allowed to initialize
1777 integer variables in DATA statements. Since Fortran 2003 BOZ literals
1778 are also allowed as argument of @code{REAL}, @code{DBLE}, @code{INT}
1779 and @code{CMPLX}; the result is the same as if the integer BOZ
1780 literal had been converted by @code{TRANSFER} to, respectively,
1781 @code{real}, @code{double precision}, @code{integer} or @code{complex}.
1782 As GNU Fortran extension the intrinsic procedures @code{FLOAT},
1783 @code{DFLOAT}, @code{COMPLEX} and @code{DCMPLX} are treated alike.
1784
1785 As an extension, GNU Fortran allows hexadecimal BOZ literal constants to
1786 be specified using the @code{X} prefix, in addition to the standard
1787 @code{Z} prefix. The BOZ literal can also be specified by adding a
1788 suffix to the string, for example, @code{Z'ABC'} and @code{'ABC'Z} are
1789 equivalent.
1790
1791 Furthermore, GNU Fortran allows using BOZ literal constants outside
1792 DATA statements and the four intrinsic functions allowed by Fortran 2003.
1793 In DATA statements, in direct assignments, where the right-hand side
1794 only contains a BOZ literal constant, and for old-style initializers of
1795 the form @code{integer i /o'0173'/}, the constant is transferred
1796 as if @code{TRANSFER} had been used; for @code{COMPLEX} numbers, only
1797 the real part is initialized unless @code{CMPLX} is used. In all other
1798 cases, the BOZ literal constant is converted to an @code{INTEGER} value with
1799 the largest decimal representation. This value is then converted
1800 numerically to the type and kind of the variable in question.
1801 (For instance, @code{real :: r = b'0000001' + 1} initializes @code{r}
1802 with @code{2.0}.) As different compilers implement the extension
1803 differently, one should be careful when doing bitwise initialization
1804 of non-integer variables.
1805
1806 Note that initializing an @code{INTEGER} variable with a statement such
1807 as @code{DATA i/Z'FFFFFFFF'/} will give an integer overflow error rather
1808 than the desired result of @math{-1} when @code{i} is a 32-bit integer
1809 on a system that supports 64-bit integers. The @samp{-fno-range-check}
1810 option can be used as a workaround for legacy code that initializes
1811 integers in this manner.
1812
1813 @node Real array indices
1814 @subsection Real array indices
1815 @cindex array, indices of type real
1816
1817 As an extension, GNU Fortran allows the use of @code{REAL} expressions
1818 or variables as array indices.
1819
1820 @node Unary operators
1821 @subsection Unary operators
1822 @cindex operators, unary
1823
1824 As an extension, GNU Fortran allows unary plus and unary minus operators
1825 to appear as the second operand of binary arithmetic operators without
1826 the need for parenthesis.
1827
1828 @smallexample
1829 X = Y * -Z
1830 @end smallexample
1831
1832 @node Implicitly convert LOGICAL and INTEGER values
1833 @subsection Implicitly convert @code{LOGICAL} and @code{INTEGER} values
1834 @cindex conversion, to integer
1835 @cindex conversion, to logical
1836
1837 As an extension for backwards compatibility with other compilers, GNU
1838 Fortran allows the implicit conversion of @code{LOGICAL} values to
1839 @code{INTEGER} values and vice versa. When converting from a
1840 @code{LOGICAL} to an @code{INTEGER}, @code{.FALSE.} is interpreted as
1841 zero, and @code{.TRUE.} is interpreted as one. When converting from
1842 @code{INTEGER} to @code{LOGICAL}, the value zero is interpreted as
1843 @code{.FALSE.} and any nonzero value is interpreted as @code{.TRUE.}.
1844
1845 @smallexample
1846 LOGICAL :: l
1847 l = 1
1848 @end smallexample
1849 @smallexample
1850 INTEGER :: i
1851 i = .TRUE.
1852 @end smallexample
1853
1854 However, there is no implicit conversion of @code{INTEGER} values in
1855 @code{if}-statements, nor of @code{LOGICAL} or @code{INTEGER} values
1856 in I/O operations.
1857
1858 @node Hollerith constants support
1859 @subsection Hollerith constants support
1860 @cindex Hollerith constants
1861
1862 GNU Fortran supports Hollerith constants in assignments, function
1863 arguments, and @code{DATA} and @code{ASSIGN} statements. A Hollerith
1864 constant is written as a string of characters preceded by an integer
1865 constant indicating the character count, and the letter @code{H} or
1866 @code{h}, and stored in bytewise fashion in a numeric (@code{INTEGER},
1867 @code{REAL}, or @code{complex}) or @code{LOGICAL} variable. The
1868 constant will be padded or truncated to fit the size of the variable in
1869 which it is stored.
1870
1871 Examples of valid uses of Hollerith constants:
1872 @smallexample
1873 complex*16 x(2)
1874 data x /16Habcdefghijklmnop, 16Hqrstuvwxyz012345/
1875 x(1) = 16HABCDEFGHIJKLMNOP
1876 call foo (4h abc)
1877 @end smallexample
1878
1879 Invalid Hollerith constants examples:
1880 @smallexample
1881 integer*4 a
1882 a = 8H12345678 ! Valid, but the Hollerith constant will be truncated.
1883 a = 0H ! At least one character is needed.
1884 @end smallexample
1885
1886 In general, Hollerith constants were used to provide a rudimentary
1887 facility for handling character strings in early Fortran compilers,
1888 prior to the introduction of @code{CHARACTER} variables in Fortran 77;
1889 in those cases, the standard-compliant equivalent is to convert the
1890 program to use proper character strings. On occasion, there may be a
1891 case where the intent is specifically to initialize a numeric variable
1892 with a given byte sequence. In these cases, the same result can be
1893 obtained by using the @code{TRANSFER} statement, as in this example.
1894 @smallexample
1895 INTEGER(KIND=4) :: a
1896 a = TRANSFER ("abcd", a) ! equivalent to: a = 4Habcd
1897 @end smallexample
1898
1899
1900 @node Cray pointers
1901 @subsection Cray pointers
1902 @cindex pointer, Cray
1903
1904 Cray pointers are part of a non-standard extension that provides a
1905 C-like pointer in Fortran. This is accomplished through a pair of
1906 variables: an integer "pointer" that holds a memory address, and a
1907 "pointee" that is used to dereference the pointer.
1908
1909 Pointer/pointee pairs are declared in statements of the form:
1910 @smallexample
1911 pointer ( <pointer> , <pointee> )
1912 @end smallexample
1913 or,
1914 @smallexample
1915 pointer ( <pointer1> , <pointee1> ), ( <pointer2> , <pointee2> ), ...
1916 @end smallexample
1917 The pointer is an integer that is intended to hold a memory address.
1918 The pointee may be an array or scalar.
1919 If an assumed-size array is permitted within the scoping unit, a
1920 pointee can be an assumed-size array.
1921 That is, the last dimension may be left unspecified by using a @code{*}
1922 in place of a value. A pointee cannot be an assumed shape array.
1923 No space is allocated for the pointee.
1924
1925 The pointee may have its type declared before or after the pointer
1926 statement, and its array specification (if any) may be declared
1927 before, during, or after the pointer statement. The pointer may be
1928 declared as an integer prior to the pointer statement. However, some
1929 machines have default integer sizes that are different than the size
1930 of a pointer, and so the following code is not portable:
1931 @smallexample
1932 integer ipt
1933 pointer (ipt, iarr)
1934 @end smallexample
1935 If a pointer is declared with a kind that is too small, the compiler
1936 will issue a warning; the resulting binary will probably not work
1937 correctly, because the memory addresses stored in the pointers may be
1938 truncated. It is safer to omit the first line of the above example;
1939 if explicit declaration of ipt's type is omitted, then the compiler
1940 will ensure that ipt is an integer variable large enough to hold a
1941 pointer.
1942
1943 Pointer arithmetic is valid with Cray pointers, but it is not the same
1944 as C pointer arithmetic. Cray pointers are just ordinary integers, so
1945 the user is responsible for determining how many bytes to add to a
1946 pointer in order to increment it. Consider the following example:
1947 @smallexample
1948 real target(10)
1949 real pointee(10)
1950 pointer (ipt, pointee)
1951 ipt = loc (target)
1952 ipt = ipt + 1
1953 @end smallexample
1954 The last statement does not set @code{ipt} to the address of
1955 @code{target(1)}, as it would in C pointer arithmetic. Adding @code{1}
1956 to @code{ipt} just adds one byte to the address stored in @code{ipt}.
1957
1958 Any expression involving the pointee will be translated to use the
1959 value stored in the pointer as the base address.
1960
1961 To get the address of elements, this extension provides an intrinsic
1962 function @code{LOC()}. The @code{LOC()} function is equivalent to the
1963 @code{&} operator in C, except the address is cast to an integer type:
1964 @smallexample
1965 real ar(10)
1966 pointer(ipt, arpte(10))
1967 real arpte
1968 ipt = loc(ar) ! Makes arpte is an alias for ar
1969 arpte(1) = 1.0 ! Sets ar(1) to 1.0
1970 @end smallexample
1971 The pointer can also be set by a call to the @code{MALLOC} intrinsic
1972 (see @ref{MALLOC}).
1973
1974 Cray pointees often are used to alias an existing variable. For
1975 example:
1976 @smallexample
1977 integer target(10)
1978 integer iarr(10)
1979 pointer (ipt, iarr)
1980 ipt = loc(target)
1981 @end smallexample
1982 As long as @code{ipt} remains unchanged, @code{iarr} is now an alias for
1983 @code{target}. The optimizer, however, will not detect this aliasing, so
1984 it is unsafe to use @code{iarr} and @code{target} simultaneously. Using
1985 a pointee in any way that violates the Fortran aliasing rules or
1986 assumptions is illegal. It is the user's responsibility to avoid doing
1987 this; the compiler works under the assumption that no such aliasing
1988 occurs.
1989
1990 Cray pointers will work correctly when there is no aliasing (i.e., when
1991 they are used to access a dynamically allocated block of memory), and
1992 also in any routine where a pointee is used, but any variable with which
1993 it shares storage is not used. Code that violates these rules may not
1994 run as the user intends. This is not a bug in the optimizer; any code
1995 that violates the aliasing rules is illegal. (Note that this is not
1996 unique to GNU Fortran; any Fortran compiler that supports Cray pointers
1997 will ``incorrectly'' optimize code with illegal aliasing.)
1998
1999 There are a number of restrictions on the attributes that can be applied
2000 to Cray pointers and pointees. Pointees may not have the
2001 @code{ALLOCATABLE}, @code{INTENT}, @code{OPTIONAL}, @code{DUMMY},
2002 @code{TARGET}, @code{INTRINSIC}, or @code{POINTER} attributes. Pointers
2003 may not have the @code{DIMENSION}, @code{POINTER}, @code{TARGET},
2004 @code{ALLOCATABLE}, @code{EXTERNAL}, or @code{INTRINSIC} attributes, nor
2005 may they be function results. Pointees may not occur in more than one
2006 pointer statement. A pointee cannot be a pointer. Pointees cannot occur
2007 in equivalence, common, or data statements.
2008
2009 A Cray pointer may also point to a function or a subroutine. For
2010 example, the following excerpt is valid:
2011 @smallexample
2012 implicit none
2013 external sub
2014 pointer (subptr,subpte)
2015 external subpte
2016 subptr = loc(sub)
2017 call subpte()
2018 [...]
2019 subroutine sub
2020 [...]
2021 end subroutine sub
2022 @end smallexample
2023
2024 A pointer may be modified during the course of a program, and this
2025 will change the location to which the pointee refers. However, when
2026 pointees are passed as arguments, they are treated as ordinary
2027 variables in the invoked function. Subsequent changes to the pointer
2028 will not change the base address of the array that was passed.
2029
2030 @node CONVERT specifier
2031 @subsection @code{CONVERT} specifier
2032 @cindex @code{CONVERT} specifier
2033
2034 GNU Fortran allows the conversion of unformatted data between little-
2035 and big-endian representation to facilitate moving of data
2036 between different systems. The conversion can be indicated with
2037 the @code{CONVERT} specifier on the @code{OPEN} statement.
2038 @xref{GFORTRAN_CONVERT_UNIT}, for an alternative way of specifying
2039 the data format via an environment variable.
2040
2041 Valid values for @code{CONVERT} are:
2042 @itemize @w{}
2043 @item @code{CONVERT='NATIVE'} Use the native format. This is the default.
2044 @item @code{CONVERT='SWAP'} Swap between little- and big-endian.
2045 @item @code{CONVERT='LITTLE_ENDIAN'} Use the little-endian representation
2046 for unformatted files.
2047 @item @code{CONVERT='BIG_ENDIAN'} Use the big-endian representation for
2048 unformatted files.
2049 @end itemize
2050
2051 Using the option could look like this:
2052 @smallexample
2053 open(file='big.dat',form='unformatted',access='sequential', &
2054 convert='big_endian')
2055 @end smallexample
2056
2057 The value of the conversion can be queried by using
2058 @code{INQUIRE(CONVERT=ch)}. The values returned are
2059 @code{'BIG_ENDIAN'} and @code{'LITTLE_ENDIAN'}.
2060
2061 @code{CONVERT} works between big- and little-endian for
2062 @code{INTEGER} values of all supported kinds and for @code{REAL}
2063 on IEEE systems of kinds 4 and 8. Conversion between different
2064 ``extended double'' types on different architectures such as
2065 m68k and x86_64, which GNU Fortran
2066 supports as @code{REAL(KIND=10)} and @code{REAL(KIND=16)}, will
2067 probably not work.
2068
2069 @emph{Note that the values specified via the GFORTRAN_CONVERT_UNIT
2070 environment variable will override the CONVERT specifier in the
2071 open statement}. This is to give control over data formats to
2072 users who do not have the source code of their program available.
2073
2074 Using anything but the native representation for unformatted data
2075 carries a significant speed overhead. If speed in this area matters
2076 to you, it is best if you use this only for data that needs to be
2077 portable.
2078
2079 @node OpenMP
2080 @subsection OpenMP
2081 @cindex OpenMP
2082
2083 OpenMP (Open Multi-Processing) is an application programming
2084 interface (API) that supports multi-platform shared memory
2085 multiprocessing programming in C/C++ and Fortran on many
2086 architectures, including Unix and Microsoft Windows platforms.
2087 It consists of a set of compiler directives, library routines,
2088 and environment variables that influence run-time behavior.
2089
2090 GNU Fortran strives to be compatible to the
2091 @uref{http://openmp.org/wp/openmp-specifications/,
2092 OpenMP Application Program Interface v4.5}.
2093
2094 To enable the processing of the OpenMP directive @code{!$omp} in
2095 free-form source code; the @code{c$omp}, @code{*$omp} and @code{!$omp}
2096 directives in fixed form; the @code{!$} conditional compilation sentinels
2097 in free form; and the @code{c$}, @code{*$} and @code{!$} sentinels
2098 in fixed form, @command{gfortran} needs to be invoked with the
2099 @option{-fopenmp}. This also arranges for automatic linking of the
2100 GNU Offloading and Multi Processing Runtime Library
2101 @ref{Top,,libgomp,libgomp,GNU Offloading and Multi Processing Runtime
2102 Library}.
2103
2104 The OpenMP Fortran runtime library routines are provided both in a
2105 form of a Fortran 90 module named @code{omp_lib} and in a form of
2106 a Fortran @code{include} file named @file{omp_lib.h}.
2107
2108 An example of a parallelized loop taken from Appendix A.1 of
2109 the OpenMP Application Program Interface v2.5:
2110 @smallexample
2111 SUBROUTINE A1(N, A, B)
2112 INTEGER I, N
2113 REAL B(N), A(N)
2114 !$OMP PARALLEL DO !I is private by default
2115 DO I=2,N
2116 B(I) = (A(I) + A(I-1)) / 2.0
2117 ENDDO
2118 !$OMP END PARALLEL DO
2119 END SUBROUTINE A1
2120 @end smallexample
2121
2122 Please note:
2123 @itemize
2124 @item
2125 @option{-fopenmp} implies @option{-frecursive}, i.e., all local arrays
2126 will be allocated on the stack. When porting existing code to OpenMP,
2127 this may lead to surprising results, especially to segmentation faults
2128 if the stacksize is limited.
2129
2130 @item
2131 On glibc-based systems, OpenMP enabled applications cannot be statically
2132 linked due to limitations of the underlying pthreads-implementation. It
2133 might be possible to get a working solution if
2134 @command{-Wl,--whole-archive -lpthread -Wl,--no-whole-archive} is added
2135 to the command line. However, this is not supported by @command{gcc} and
2136 thus not recommended.
2137 @end itemize
2138
2139 @node OpenACC
2140 @subsection OpenACC
2141 @cindex OpenACC
2142
2143 OpenACC is an application programming interface (API) that supports
2144 offloading of code to accelerator devices. It consists of a set of
2145 compiler directives, library routines, and environment variables that
2146 influence run-time behavior.
2147
2148 GNU Fortran strives to be compatible to the
2149 @uref{http://www.openacc.org/, OpenACC Application Programming
2150 Interface v2.0}.
2151
2152 To enable the processing of the OpenACC directive @code{!$acc} in
2153 free-form source code; the @code{c$acc}, @code{*$acc} and @code{!$acc}
2154 directives in fixed form; the @code{!$} conditional compilation
2155 sentinels in free form; and the @code{c$}, @code{*$} and @code{!$}
2156 sentinels in fixed form, @command{gfortran} needs to be invoked with
2157 the @option{-fopenacc}. This also arranges for automatic linking of
2158 the GNU Offloading and Multi Processing Runtime Library
2159 @ref{Top,,libgomp,libgomp,GNU Offloading and Multi Processing Runtime
2160 Library}.
2161
2162 The OpenACC Fortran runtime library routines are provided both in a
2163 form of a Fortran 90 module named @code{openacc} and in a form of a
2164 Fortran @code{include} file named @file{openacc_lib.h}.
2165
2166 Note that this is an experimental feature, incomplete, and subject to
2167 change in future versions of GCC. See
2168 @uref{https://gcc.gnu.org/wiki/OpenACC} for more information.
2169
2170 @node Argument list functions
2171 @subsection Argument list functions @code{%VAL}, @code{%REF} and @code{%LOC}
2172 @cindex argument list functions
2173 @cindex @code{%VAL}
2174 @cindex @code{%REF}
2175 @cindex @code{%LOC}
2176
2177 GNU Fortran supports argument list functions @code{%VAL}, @code{%REF}
2178 and @code{%LOC} statements, for backward compatibility with g77.
2179 It is recommended that these should be used only for code that is
2180 accessing facilities outside of GNU Fortran, such as operating system
2181 or windowing facilities. It is best to constrain such uses to isolated
2182 portions of a program--portions that deal specifically and exclusively
2183 with low-level, system-dependent facilities. Such portions might well
2184 provide a portable interface for use by the program as a whole, but are
2185 themselves not portable, and should be thoroughly tested each time they
2186 are rebuilt using a new compiler or version of a compiler.
2187
2188 @code{%VAL} passes a scalar argument by value, @code{%REF} passes it by
2189 reference and @code{%LOC} passes its memory location. Since gfortran
2190 already passes scalar arguments by reference, @code{%REF} is in effect
2191 a do-nothing. @code{%LOC} has the same effect as a Fortran pointer.
2192
2193 An example of passing an argument by value to a C subroutine foo.:
2194 @smallexample
2195 C
2196 C prototype void foo_ (float x);
2197 C
2198 external foo
2199 real*4 x
2200 x = 3.14159
2201 call foo (%VAL (x))
2202 end
2203 @end smallexample
2204
2205 For details refer to the g77 manual
2206 @uref{https://gcc.gnu.org/@/onlinedocs/@/gcc-3.4.6/@/g77/@/index.html#Top}.
2207
2208 Also, @code{c_by_val.f} and its partner @code{c_by_val.c} of the
2209 GNU Fortran testsuite are worth a look.
2210
2211 @node Read/Write after EOF marker
2212 @subsection Read/Write after EOF marker
2213 @cindex @code{EOF}
2214 @cindex @code{BACKSPACE}
2215 @cindex @code{REWIND}
2216
2217 Some legacy codes rely on allowing @code{READ} or @code{WRITE} after the
2218 EOF file marker in order to find the end of a file. GNU Fortran normally
2219 rejects these codes with a run-time error message and suggests the user
2220 consider @code{BACKSPACE} or @code{REWIND} to properly position
2221 the file before the EOF marker. As an extension, the run-time error may
2222 be disabled using -std=legacy.
2223
2224
2225 @node STRUCTURE and RECORD
2226 @subsection @code{STRUCTURE} and @code{RECORD}
2227 @cindex @code{STRUCTURE}
2228 @cindex @code{RECORD}
2229
2230 Record structures are a pre-Fortran-90 vendor extension to create
2231 user-defined aggregate data types. Support for record structures in GNU
2232 Fortran can be enabled with the @option{-fdec-structure} compile flag.
2233 If you have a choice, you should instead use Fortran 90's ``derived types'',
2234 which have a different syntax.
2235
2236 In many cases, record structures can easily be converted to derived types.
2237 To convert, replace @code{STRUCTURE /}@var{structure-name}@code{/}
2238 by @code{TYPE} @var{type-name}. Additionally, replace
2239 @code{RECORD /}@var{structure-name}@code{/} by
2240 @code{TYPE(}@var{type-name}@code{)}. Finally, in the component access,
2241 replace the period (@code{.}) by the percent sign (@code{%}).
2242
2243 Here is an example of code using the non portable record structure syntax:
2244
2245 @example
2246 ! Declaring a structure named ``item'' and containing three fields:
2247 ! an integer ID, an description string and a floating-point price.
2248 STRUCTURE /item/
2249 INTEGER id
2250 CHARACTER(LEN=200) description
2251 REAL price
2252 END STRUCTURE
2253
2254 ! Define two variables, an single record of type ``item''
2255 ! named ``pear'', and an array of items named ``store_catalog''
2256 RECORD /item/ pear, store_catalog(100)
2257
2258 ! We can directly access the fields of both variables
2259 pear.id = 92316
2260 pear.description = "juicy D'Anjou pear"
2261 pear.price = 0.15
2262 store_catalog(7).id = 7831
2263 store_catalog(7).description = "milk bottle"
2264 store_catalog(7).price = 1.2
2265
2266 ! We can also manipulate the whole structure
2267 store_catalog(12) = pear
2268 print *, store_catalog(12)
2269 @end example
2270
2271 @noindent
2272 This code can easily be rewritten in the Fortran 90 syntax as following:
2273
2274 @example
2275 ! ``STRUCTURE /name/ ... END STRUCTURE'' becomes
2276 ! ``TYPE name ... END TYPE''
2277 TYPE item
2278 INTEGER id
2279 CHARACTER(LEN=200) description
2280 REAL price
2281 END TYPE
2282
2283 ! ``RECORD /name/ variable'' becomes ``TYPE(name) variable''
2284 TYPE(item) pear, store_catalog(100)
2285
2286 ! Instead of using a dot (.) to access fields of a record, the
2287 ! standard syntax uses a percent sign (%)
2288 pear%id = 92316
2289 pear%description = "juicy D'Anjou pear"
2290 pear%price = 0.15
2291 store_catalog(7)%id = 7831
2292 store_catalog(7)%description = "milk bottle"
2293 store_catalog(7)%price = 1.2
2294
2295 ! Assignments of a whole variable do not change
2296 store_catalog(12) = pear
2297 print *, store_catalog(12)
2298 @end example
2299
2300 @noindent
2301 GNU Fortran implements STRUCTURES like derived types with the following
2302 rules and exceptions:
2303
2304 @itemize @bullet
2305 @item Structures act like derived types with the @code{SEQUENCE} attribute.
2306 Otherwise they may contain no specifiers.
2307
2308 @item Structures may contain a special field with the name @code{%FILL}.
2309 This will create an anonymous component which cannot be accessed but occupies
2310 space just as if a component of the same type was declared in its place, useful
2311 for alignment purposes. As an example, the following structure will consist
2312 of at least sixteen bytes:
2313
2314 @smallexample
2315 structure /padded/
2316 character(4) start
2317 character(8) %FILL
2318 character(4) end
2319 end structure
2320 @end smallexample
2321
2322 @item Structures may share names with other symbols. For example, the following
2323 is invalid for derived types, but valid for structures:
2324
2325 @smallexample
2326 structure /header/
2327 ! ...
2328 end structure
2329 record /header/ header
2330 @end smallexample
2331
2332 @item Structure types may be declared nested within another parent structure.
2333 The syntax is:
2334 @smallexample
2335 structure /type-name/
2336 ...
2337 structure [/<type-name>/] <field-list>
2338 ...
2339 @end smallexample
2340
2341 The type name may be ommitted, in which case the structure type itself is
2342 anonymous, and other structures of the same type cannot be instantiated. The
2343 following shows some examples:
2344
2345 @example
2346 structure /appointment/
2347 ! nested structure definition: app_time is an array of two 'time'
2348 structure /time/ app_time (2)
2349 integer(1) hour, minute
2350 end structure
2351 character(10) memo
2352 end structure
2353
2354 ! The 'time' structure is still usable
2355 record /time/ now
2356 now = time(5, 30)
2357
2358 ...
2359
2360 structure /appointment/
2361 ! anonymous nested structure definition
2362 structure start, end
2363 integer(1) hour, minute
2364 end structure
2365 character(10) memo
2366 end structure
2367 @end example
2368
2369 @item Structures may contain @code{UNION} blocks. For more detail see the
2370 section on @ref{UNION and MAP}.
2371
2372 @item Structures support old-style initialization of components, like
2373 those described in @ref{Old-style variable initialization}. For array
2374 initializers, an initializer may contain a repeat specification of the form
2375 @code{<literal-integer> * <constant-initializer>}. The value of the integer
2376 indicates the number of times to repeat the constant initializer when expanding
2377 the initializer list.
2378 @end itemize
2379
2380 @node UNION and MAP
2381 @subsection @code{UNION} and @code{MAP}
2382 @cindex @code{UNION}
2383 @cindex @code{MAP}
2384
2385 Unions are an old vendor extension which were commonly used with the
2386 non-standard @ref{STRUCTURE and RECORD} extensions. Use of @code{UNION} and
2387 @code{MAP} is automatically enabled with @option{-fdec-structure}.
2388
2389 A @code{UNION} declaration occurs within a structure; within the definition of
2390 each union is a number of @code{MAP} blocks. Each @code{MAP} shares storage
2391 with its sibling maps (in the same union), and the size of the union is the
2392 size of the largest map within it, just as with unions in C. The major
2393 difference is that component references do not indicate which union or map the
2394 component is in (the compiler gets to figure that out).
2395
2396 Here is a small example:
2397 @smallexample
2398 structure /myunion/
2399 union
2400 map
2401 character(2) w0, w1, w2
2402 end map
2403 map
2404 character(6) long
2405 end map
2406 end union
2407 end structure
2408
2409 record /myunion/ rec
2410 ! After this assignment...
2411 rec.long = 'hello!'
2412
2413 ! The following is true:
2414 ! rec.w0 === 'he'
2415 ! rec.w1 === 'll'
2416 ! rec.w2 === 'o!'
2417 @end smallexample
2418
2419 The two maps share memory, and the size of the union is ultimately six bytes:
2420
2421 @example
2422 0 1 2 3 4 5 6 Byte offset
2423 -------------------------------
2424 | | | | | | |
2425 -------------------------------
2426
2427 ^ W0 ^ W1 ^ W2 ^
2428 \-------/ \-------/ \-------/
2429
2430 ^ LONG ^
2431 \---------------------------/
2432 @end example
2433
2434 Following is an example mirroring the layout of an Intel x86_64 register:
2435
2436 @example
2437 structure /reg/
2438 union ! U0 ! rax
2439 map
2440 character(16) rx
2441 end map
2442 map
2443 character(8) rh ! rah
2444 union ! U1
2445 map
2446 character(8) rl ! ral
2447 end map
2448 map
2449 character(8) ex ! eax
2450 end map
2451 map
2452 character(4) eh ! eah
2453 union ! U2
2454 map
2455 character(4) el ! eal
2456 end map
2457 map
2458 character(4) x ! ax
2459 end map
2460 map
2461 character(2) h ! ah
2462 character(2) l ! al
2463 end map
2464 end union
2465 end map
2466 end union
2467 end map
2468 end union
2469 end structure
2470 record /reg/ a
2471
2472 ! After this assignment...
2473 a.rx = 'AAAAAAAA.BBB.C.D'
2474
2475 ! The following is true:
2476 a.rx === 'AAAAAAAA.BBB.C.D'
2477 a.rh === 'AAAAAAAA'
2478 a.rl === '.BBB.C.D'
2479 a.ex === '.BBB.C.D'
2480 a.eh === '.BBB'
2481 a.el === '.C.D'
2482 a.x === '.C.D'
2483 a.h === '.C'
2484 a.l === '.D'
2485 @end example
2486
2487 @node Type variants for integer intrinsics
2488 @subsection Type variants for integer intrinsics
2489 @cindex intrinsics, integer
2490
2491 Similar to the D/C prefixes to real functions to specify the input/output
2492 types, GNU Fortran offers B/I/J/K prefixes to integer functions for
2493 compatibility with DEC programs. The types implied by each are:
2494
2495 @example
2496 @code{B} - @code{INTEGER(kind=1)}
2497 @code{I} - @code{INTEGER(kind=2)}
2498 @code{J} - @code{INTEGER(kind=4)}
2499 @code{K} - @code{INTEGER(kind=8)}
2500 @end example
2501
2502 GNU Fortran supports these with the flag @option{-fdec-intrinsic-ints}.
2503 Intrinsics for which prefixed versions are available and in what form are noted
2504 in @ref{Intrinsic Procedures}. The complete list of supported intrinsics is
2505 here:
2506
2507 @multitable @columnfractions .2 .2 .2 .2 .2
2508
2509 @headitem Intrinsic @tab B @tab I @tab J @tab K
2510
2511 @item @code{@ref{ABS}}
2512 @tab @code{BABS} @tab @code{IIABS} @tab @code{JIABS} @tab @code{KIABS}
2513 @item @code{@ref{BTEST}}
2514 @tab @code{BBTEST} @tab @code{BITEST} @tab @code{BJTEST} @tab @code{BKTEST}
2515 @item @code{@ref{IAND}}
2516 @tab @code{BIAND} @tab @code{IIAND} @tab @code{JIAND} @tab @code{KIAND}
2517 @item @code{@ref{IBCLR}}
2518 @tab @code{BBCLR} @tab @code{IIBCLR} @tab @code{JIBCLR} @tab @code{KIBCLR}
2519 @item @code{@ref{IBITS}}
2520 @tab @code{BBITS} @tab @code{IIBITS} @tab @code{JIBITS} @tab @code{KIBITS}
2521 @item @code{@ref{IBSET}}
2522 @tab @code{BBSET} @tab @code{IIBSET} @tab @code{JIBSET} @tab @code{KIBSET}
2523 @item @code{@ref{IEOR}}
2524 @tab @code{BIEOR} @tab @code{IIEOR} @tab @code{JIEOR} @tab @code{KIEOR}
2525 @item @code{@ref{IOR}}
2526 @tab @code{BIOR} @tab @code{IIOR} @tab @code{JIOR} @tab @code{KIOR}
2527 @item @code{@ref{ISHFT}}
2528 @tab @code{BSHFT} @tab @code{IISHFT} @tab @code{JISHFT} @tab @code{KISHFT}
2529 @item @code{@ref{ISHFTC}}
2530 @tab @code{BSHFTC} @tab @code{IISHFTC} @tab @code{JISHFTC} @tab @code{KISHFTC}
2531 @item @code{@ref{MOD}}
2532 @tab @code{BMOD} @tab @code{IMOD} @tab @code{JMOD} @tab @code{KMOD}
2533 @item @code{@ref{NOT}}
2534 @tab @code{BNOT} @tab @code{INOT} @tab @code{JNOT} @tab @code{KNOT}
2535 @item @code{@ref{REAL}}
2536 @tab @code{--} @tab @code{FLOATI} @tab @code{FLOATJ} @tab @code{FLOATK}
2537 @end multitable
2538
2539 @node AUTOMATIC and STATIC attributes
2540 @subsection @code{AUTOMATIC} and @code{STATIC} attributes
2541 @cindex variable attributes
2542 @cindex @code{AUTOMATIC}
2543 @cindex @code{STATIC}
2544
2545 With @option{-fdec-static} GNU Fortran supports the DEC extended attributes
2546 @code{STATIC} and @code{AUTOMATIC} to provide explicit specification of entity
2547 storage. These follow the syntax of the Fortran standard @code{SAVE} attribute.
2548
2549 @code{STATIC} is exactly equivalent to @code{SAVE}, and specifies that
2550 an entity should be allocated in static memory. As an example, @code{STATIC}
2551 local variables will retain their values across multiple calls to a function.
2552
2553 Entities marked @code{AUTOMATIC} will be stack automatic whenever possible.
2554 @code{AUTOMATIC} is the default for local variables smaller than
2555 @option{-fmax-stack-var-size}, unless @option{-fno-automatic} is given. This
2556 attribute overrides @option{-fno-automatic}, @option{-fmax-stack-var-size}, and
2557 blanket @code{SAVE} statements.
2558
2559
2560 Examples:
2561
2562 @example
2563 subroutine f
2564 integer, automatic :: i ! automatic variable
2565 integer x, y ! static variables
2566 save
2567 ...
2568 endsubroutine
2569 @end example
2570 @example
2571 subroutine f
2572 integer a, b, c, x, y, z
2573 static :: x
2574 save y
2575 automatic z, c
2576 ! a, b, c, and z are automatic
2577 ! x and y are static
2578 endsubroutine
2579 @end example
2580 @example
2581 ! Compiled with -fno-automatic
2582 subroutine f
2583 integer a, b, c, d
2584 automatic :: a
2585 ! a is automatic; b, c, and d are static
2586 endsubroutine
2587 @end example
2588
2589 @node Extended math intrinsics
2590 @subsection Extended math intrinsics
2591 @cindex intrinsics, math
2592 @cindex intrinsics, trigonometric functions
2593
2594 GNU Fortran supports an extended list of mathematical intrinsics with the
2595 compile flag @option{-fdec-math} for compatability with legacy code.
2596 These intrinsics are described fully in @ref{Intrinsic Procedures} where it is
2597 noted that they are extensions and should be avoided whenever possible.
2598
2599 Specifically, @option{-fdec-math} enables the @ref{COTAN} intrinsic, and
2600 trigonometric intrinsics which accept or produce values in degrees instead of
2601 radians. Here is a summary of the new intrinsics:
2602
2603 @multitable @columnfractions .5 .5
2604 @headitem Radians @tab Degrees
2605 @item @code{@ref{ACOS}} @tab @code{@ref{ACOSD}}*
2606 @item @code{@ref{ASIN}} @tab @code{@ref{ASIND}}*
2607 @item @code{@ref{ATAN}} @tab @code{@ref{ATAND}}*
2608 @item @code{@ref{ATAN2}} @tab @code{@ref{ATAN2D}}*
2609 @item @code{@ref{COS}} @tab @code{@ref{COSD}}*
2610 @item @code{@ref{COTAN}}* @tab @code{@ref{COTAND}}*
2611 @item @code{@ref{SIN}} @tab @code{@ref{SIND}}*
2612 @item @code{@ref{TAN}} @tab @code{@ref{TAND}}*
2613 @end multitable
2614
2615 * Enabled with @option{-fdec-math}.
2616
2617 For advanced users, it may be important to know the implementation of these
2618 functions. They are simply wrappers around the standard radian functions, which
2619 have more accurate builtin versions. These functions convert their arguments
2620 (or results) to degrees (or radians) by taking the value modulus 360 (or 2*pi)
2621 and then multiplying it by a constant radian-to-degree (or degree-to-radian)
2622 factor, as appropriate. The factor is computed at compile-time as 180/pi (or
2623 pi/180).
2624
2625 @node Form feed as whitespace
2626 @subsection Form feed as whitespace
2627 @cindex form feed whitespace
2628
2629 Historically, legacy compilers allowed insertion of form feed characters ('\f',
2630 ASCII 0xC) at the beginning of lines for formatted output to line printers,
2631 though the Fortran standard does not mention this. GNU Fortran supports the
2632 interpretation of form feed characters in source as whitespace for
2633 compatibility.
2634
2635 @node TYPE as an alias for PRINT
2636 @subsection TYPE as an alias for PRINT
2637 @cindex type alias print
2638 For compatibility, GNU Fortran will interpret @code{TYPE} statements as
2639 @code{PRINT} statements with the flag @option{-fdec}. With this flag asserted,
2640 the following two examples are equivalent:
2641
2642 @smallexample
2643 TYPE *, 'hello world'
2644 @end smallexample
2645
2646 @smallexample
2647 PRINT *, 'hello world'
2648 @end smallexample
2649
2650 @node %LOC as an rvalue
2651 @subsection %LOC as an rvalue
2652 @cindex LOC
2653 Normally @code{%LOC} is allowed only in parameter lists. However the intrinsic
2654 function @code{LOC} does the same thing, and is usable as the right-hand-side of
2655 assignments. For compatibility, GNU Fortran supports the use of @code{%LOC} as
2656 an alias for the builtin @code{LOC} with @option{-std=legacy}. With this
2657 feature enabled the following two examples are equivalent:
2658
2659 @smallexample
2660 integer :: i, l
2661 l = %loc(i)
2662 call sub(l)
2663 @end smallexample
2664
2665 @smallexample
2666 integer :: i
2667 call sub(%loc(i))
2668 @end smallexample
2669
2670 @node .XOR. operator
2671 @subsection .XOR. operator
2672 @cindex operators, xor
2673
2674 GNU Fortran supports @code{.XOR.} as a logical operator with @code{-std=legacy}
2675 for compatibility with legacy code. @code{.XOR.} is equivalent to
2676 @code{.NEQV.}. That is, the output is true if and only if the inputs differ.
2677
2678 @node Bitwise logical operators
2679 @subsection Bitwise logical operators
2680 @cindex logical, bitwise
2681
2682 With @option{-fdec}, GNU Fortran relaxes the type constraints on
2683 logical operators to allow integer operands, and performs the corresponding
2684 bitwise operation instead. This flag is for compatibility only, and should be
2685 avoided in new code. Consider:
2686
2687 @smallexample
2688 INTEGER :: i, j
2689 i = z'33'
2690 j = z'cc'
2691 print *, i .AND. j
2692 @end smallexample
2693
2694 In this example, compiled with @option{-fdec}, GNU Fortran will
2695 replace the @code{.AND.} operation with a call to the intrinsic
2696 @code{@ref{IAND}} function, yielding the bitwise-and of @code{i} and @code{j}.
2697
2698 Note that this conversion will occur if at least one operand is of integral
2699 type. As a result, a logical operand will be converted to an integer when the
2700 other operand is an integer in a logical operation. In this case,
2701 @code{.TRUE.} is converted to @code{1} and @code{.FALSE.} to @code{0}.
2702
2703 Here is the mapping of logical operator to bitwise intrinsic used with
2704 @option{-fdec}:
2705
2706 @multitable @columnfractions .25 .25 .5
2707 @headitem Operator @tab Intrinsic @tab Bitwise operation
2708 @item @code{.NOT.} @tab @code{@ref{NOT}} @tab complement
2709 @item @code{.AND.} @tab @code{@ref{IAND}} @tab intersection
2710 @item @code{.OR.} @tab @code{@ref{IOR}} @tab union
2711 @item @code{.NEQV.} @tab @code{@ref{IEOR}} @tab exclusive or
2712 @item @code{.EQV.} @tab @code{@ref{NOT}(@ref{IEOR})} @tab complement of exclusive or
2713 @end multitable
2714
2715 @node Extended I/O specifiers
2716 @subsection Extended I/O specifiers
2717 @cindex @code{CARRIAGECONTROL}
2718 @cindex @code{READONLY}
2719 @cindex @code{SHARE}
2720 @cindex @code{SHARED}
2721 @cindex @code{NOSHARED}
2722 @cindex I/O specifiers
2723
2724 GNU Fortran supports the additional legacy I/O specifiers
2725 @code{CARRIAGECONTROL}, @code{READONLY}, and @code{SHARE} with the
2726 compile flag @option{-fdec}, for compatibility.
2727
2728 @table @code
2729 @item CARRIAGECONTROL
2730 The @code{CARRIAGECONTROL} specifier allows a user to control line
2731 termination settings between output records for an I/O unit. The specifier has
2732 no meaning for readonly files. When @code{CARRAIGECONTROL} is specified upon
2733 opening a unit for formatted writing, the exact @code{CARRIAGECONTROL} setting
2734 determines what characters to write between output records. The syntax is:
2735
2736 @smallexample
2737 OPEN(..., CARRIAGECONTROL=cc)
2738 @end smallexample
2739
2740 Where @emph{cc} is a character expression that evaluates to one of the
2741 following values:
2742
2743 @multitable @columnfractions .2 .8
2744 @item @code{'LIST'} @tab One line feed between records (default)
2745 @item @code{'FORTRAN'} @tab Legacy interpretation of the first character (see below)
2746 @item @code{'NONE'} @tab No separator between records
2747 @end multitable
2748
2749 With @code{CARRIAGECONTROL='FORTRAN'}, when a record is written, the first
2750 character of the input record is not written, and instead determines the output
2751 record separator as follows:
2752
2753 @multitable @columnfractions .3 .3 .4
2754 @headitem Leading character @tab Meaning @tab Output separating character(s)
2755 @item @code{'+'} @tab Overprinting @tab Carriage return only
2756 @item @code{'-'} @tab New line @tab Line feed and carriage return
2757 @item @code{'0'} @tab Skip line @tab Two line feeds and carriage return
2758 @item @code{'1'} @tab New page @tab Form feed and carriage return
2759 @item @code{'$'} @tab Prompting @tab Line feed (no carriage return)
2760 @item @code{CHAR(0)} @tab Overprinting (no advance) @tab None
2761 @end multitable
2762
2763 @item READONLY
2764 The @code{READONLY} specifier may be given upon opening a unit, and is
2765 equivalent to specifying @code{ACTION='READ'}, except that the file may not be
2766 deleted on close (i.e. @code{CLOSE} with @code{STATUS="DELETE"}). The syntax
2767 is:
2768
2769 @smallexample
2770 @code{OPEN(..., READONLY)}
2771 @end smallexample
2772
2773 @item SHARE
2774 The @code{SHARE} specifier allows system-level locking on a unit upon opening
2775 it for controlled access from multiple processes/threads. The @code{SHARE}
2776 specifier has several forms:
2777
2778 @smallexample
2779 OPEN(..., SHARE=sh)
2780 OPEN(..., SHARED)
2781 OPEN(..., NOSHARED)
2782 @end smallexample
2783
2784 Where @emph{sh} in the first form is a character expression that evaluates to
2785 a value as seen in the table below. The latter two forms are aliases
2786 for particular values of @emph{sh}:
2787
2788 @multitable @columnfractions .3 .3 .4
2789 @headitem Explicit form @tab Short form @tab Meaning
2790 @item @code{SHARE='DENYRW'} @tab @code{NOSHARED} @tab Exclusive (write) lock
2791 @item @code{SHARE='DENYNONE'} @tab @code{SHARED} @tab Shared (read) lock
2792 @end multitable
2793
2794 In general only one process may hold an exclusive (write) lock for a given file
2795 at a time, whereas many processes may hold shared (read) locks for the same
2796 file.
2797
2798 The behavior of locking may vary with your operating system. On POSIX systems,
2799 locking is implemented with @code{fcntl}. Consult your corresponding operating
2800 system's manual pages for further details. Locking via @code{SHARE=} is not
2801 supported on other systems.
2802
2803 @end table
2804
2805 @node Legacy PARAMETER statements
2806 @subsection Legacy PARAMETER statements
2807 @cindex PARAMETER
2808
2809 For compatibility, GNU Fortran supports legacy PARAMETER statements without
2810 parentheses with @option{-std=legacy}. A warning is emitted if used with
2811 @option{-std=gnu}, and an error is acknowledged with a real Fortran standard
2812 flag (@option{-std=f95}, etc...). These statements take the following form:
2813
2814 @smallexample
2815 implicit real (E)
2816 parameter e = 2.718282
2817 real c
2818 parameter c = 3.0e8
2819 @end smallexample
2820
2821 @node Default exponents
2822 @subsection Default exponents
2823 @cindex exponent
2824
2825 For compatibility, GNU Fortran supports a default exponent of zero in real
2826 constants with @option{-fdec}. For example, @code{9e} would be
2827 interpreted as @code{9e0}, rather than an error.
2828
2829
2830 @node Extensions not implemented in GNU Fortran
2831 @section Extensions not implemented in GNU Fortran
2832 @cindex extensions, not implemented
2833
2834 The long history of the Fortran language, its wide use and broad
2835 userbase, the large number of different compiler vendors and the lack of
2836 some features crucial to users in the first standards have lead to the
2837 existence of a number of important extensions to the language. While
2838 some of the most useful or popular extensions are supported by the GNU
2839 Fortran compiler, not all existing extensions are supported. This section
2840 aims at listing these extensions and offering advice on how best make
2841 code that uses them running with the GNU Fortran compiler.
2842
2843 @c More can be found here:
2844 @c -- https://gcc.gnu.org/onlinedocs/gcc-3.4.6/g77/Missing-Features.html
2845 @c -- the list of Fortran and libgfortran bugs closed as WONTFIX:
2846 @c http://tinyurl.com/2u4h5y
2847
2848 @menu
2849 * ENCODE and DECODE statements::
2850 * Variable FORMAT expressions::
2851 @c * Q edit descriptor::
2852 @c * TYPE and ACCEPT I/O Statements::
2853 @c * DEFAULTFILE, DISPOSE and RECORDTYPE I/O specifiers::
2854 @c * Omitted arguments in procedure call::
2855 * Alternate complex function syntax::
2856 * Volatile COMMON blocks::
2857 * OPEN( ... NAME=)::
2858 @end menu
2859
2860 @node ENCODE and DECODE statements
2861 @subsection @code{ENCODE} and @code{DECODE} statements
2862 @cindex @code{ENCODE}
2863 @cindex @code{DECODE}
2864
2865 GNU Fortran does not support the @code{ENCODE} and @code{DECODE}
2866 statements. These statements are best replaced by @code{READ} and
2867 @code{WRITE} statements involving internal files (@code{CHARACTER}
2868 variables and arrays), which have been part of the Fortran standard since
2869 Fortran 77. For example, replace a code fragment like
2870
2871 @smallexample
2872 INTEGER*1 LINE(80)
2873 REAL A, B, C
2874 c ... Code that sets LINE
2875 DECODE (80, 9000, LINE) A, B, C
2876 9000 FORMAT (1X, 3(F10.5))
2877 @end smallexample
2878
2879 @noindent
2880 with the following:
2881
2882 @smallexample
2883 CHARACTER(LEN=80) LINE
2884 REAL A, B, C
2885 c ... Code that sets LINE
2886 READ (UNIT=LINE, FMT=9000) A, B, C
2887 9000 FORMAT (1X, 3(F10.5))
2888 @end smallexample
2889
2890 Similarly, replace a code fragment like
2891
2892 @smallexample
2893 INTEGER*1 LINE(80)
2894 REAL A, B, C
2895 c ... Code that sets A, B and C
2896 ENCODE (80, 9000, LINE) A, B, C
2897 9000 FORMAT (1X, 'OUTPUT IS ', 3(F10.5))
2898 @end smallexample
2899
2900 @noindent
2901 with the following:
2902
2903 @smallexample
2904 CHARACTER(LEN=80) LINE
2905 REAL A, B, C
2906 c ... Code that sets A, B and C
2907 WRITE (UNIT=LINE, FMT=9000) A, B, C
2908 9000 FORMAT (1X, 'OUTPUT IS ', 3(F10.5))
2909 @end smallexample
2910
2911
2912 @node Variable FORMAT expressions
2913 @subsection Variable @code{FORMAT} expressions
2914 @cindex @code{FORMAT}
2915
2916 A variable @code{FORMAT} expression is format statement which includes
2917 angle brackets enclosing a Fortran expression: @code{FORMAT(I<N>)}. GNU
2918 Fortran does not support this legacy extension. The effect of variable
2919 format expressions can be reproduced by using the more powerful (and
2920 standard) combination of internal output and string formats. For example,
2921 replace a code fragment like this:
2922
2923 @smallexample
2924 WRITE(6,20) INT1
2925 20 FORMAT(I<N+1>)
2926 @end smallexample
2927
2928 @noindent
2929 with the following:
2930
2931 @smallexample
2932 c Variable declaration
2933 CHARACTER(LEN=20) FMT
2934 c
2935 c Other code here...
2936 c
2937 WRITE(FMT,'("(I", I0, ")")') N+1
2938 WRITE(6,FMT) INT1
2939 @end smallexample
2940
2941 @noindent
2942 or with:
2943
2944 @smallexample
2945 c Variable declaration
2946 CHARACTER(LEN=20) FMT
2947 c
2948 c Other code here...
2949 c
2950 WRITE(FMT,*) N+1
2951 WRITE(6,"(I" // ADJUSTL(FMT) // ")") INT1
2952 @end smallexample
2953
2954
2955 @node Alternate complex function syntax
2956 @subsection Alternate complex function syntax
2957 @cindex Complex function
2958
2959 Some Fortran compilers, including @command{g77}, let the user declare
2960 complex functions with the syntax @code{COMPLEX FUNCTION name*16()}, as
2961 well as @code{COMPLEX*16 FUNCTION name()}. Both are non-standard, legacy
2962 extensions. @command{gfortran} accepts the latter form, which is more
2963 common, but not the former.
2964
2965
2966 @node Volatile COMMON blocks
2967 @subsection Volatile @code{COMMON} blocks
2968 @cindex @code{VOLATILE}
2969 @cindex @code{COMMON}
2970
2971 Some Fortran compilers, including @command{g77}, let the user declare
2972 @code{COMMON} with the @code{VOLATILE} attribute. This is
2973 invalid standard Fortran syntax and is not supported by
2974 @command{gfortran}. Note that @command{gfortran} accepts
2975 @code{VOLATILE} variables in @code{COMMON} blocks since revision 4.3.
2976
2977
2978 @node OPEN( ... NAME=)
2979 @subsection @code{OPEN( ... NAME=)}
2980 @cindex @code{NAM}
2981
2982 Some Fortran compilers, including @command{g77}, let the user declare
2983 @code{OPEN( ... NAME=)}. This is
2984 invalid standard Fortran syntax and is not supported by
2985 @command{gfortran}. @code{OPEN( ... NAME=)} should be replaced
2986 with @code{OPEN( ... FILE=)}.
2987
2988
2989
2990 @c ---------------------------------------------------------------------
2991 @c ---------------------------------------------------------------------
2992 @c Mixed-Language Programming
2993 @c ---------------------------------------------------------------------
2994
2995 @node Mixed-Language Programming
2996 @chapter Mixed-Language Programming
2997 @cindex Interoperability
2998 @cindex Mixed-language programming
2999
3000 @menu
3001 * Interoperability with C::
3002 * GNU Fortran Compiler Directives::
3003 * Non-Fortran Main Program::
3004 * Naming and argument-passing conventions::
3005 @end menu
3006
3007 This chapter is about mixed-language interoperability, but also applies
3008 if one links Fortran code compiled by different compilers. In most cases,
3009 use of the C Binding features of the Fortran 2003 standard is sufficient,
3010 and their use is highly recommended.
3011
3012
3013 @node Interoperability with C
3014 @section Interoperability with C
3015
3016 @menu
3017 * Intrinsic Types::
3018 * Derived Types and struct::
3019 * Interoperable Global Variables::
3020 * Interoperable Subroutines and Functions::
3021 * Working with Pointers::
3022 * Further Interoperability of Fortran with C::
3023 @end menu
3024
3025 Since Fortran 2003 (ISO/IEC 1539-1:2004(E)) there is a
3026 standardized way to generate procedure and derived-type
3027 declarations and global variables which are interoperable with C
3028 (ISO/IEC 9899:1999). The @code{bind(C)} attribute has been added
3029 to inform the compiler that a symbol shall be interoperable with C;
3030 also, some constraints are added. Note, however, that not
3031 all C features have a Fortran equivalent or vice versa. For instance,
3032 neither C's unsigned integers nor C's functions with variable number
3033 of arguments have an equivalent in Fortran.
3034
3035 Note that array dimensions are reversely ordered in C and that arrays in
3036 C always start with index 0 while in Fortran they start by default with
3037 1. Thus, an array declaration @code{A(n,m)} in Fortran matches
3038 @code{A[m][n]} in C and accessing the element @code{A(i,j)} matches
3039 @code{A[j-1][i-1]}. The element following @code{A(i,j)} (C: @code{A[j-1][i-1]};
3040 assuming @math{i < n}) in memory is @code{A(i+1,j)} (C: @code{A[j-1][i]}).
3041
3042 @node Intrinsic Types
3043 @subsection Intrinsic Types
3044
3045 In order to ensure that exactly the same variable type and kind is used
3046 in C and Fortran, the named constants shall be used which are defined in the
3047 @code{ISO_C_BINDING} intrinsic module. That module contains named constants
3048 for kind parameters and character named constants for the escape sequences
3049 in C. For a list of the constants, see @ref{ISO_C_BINDING}.
3050
3051 For logical types, please note that the Fortran standard only guarantees
3052 interoperability between C99's @code{_Bool} and Fortran's @code{C_Bool}-kind
3053 logicals and C99 defines that @code{true} has the value 1 and @code{false}
3054 the value 0. Using any other integer value with GNU Fortran's @code{LOGICAL}
3055 (with any kind parameter) gives an undefined result. (Passing other integer
3056 values than 0 and 1 to GCC's @code{_Bool} is also undefined, unless the
3057 integer is explicitly or implicitly casted to @code{_Bool}.)
3058
3059
3060
3061 @node Derived Types and struct
3062 @subsection Derived Types and struct
3063
3064 For compatibility of derived types with @code{struct}, one needs to use
3065 the @code{BIND(C)} attribute in the type declaration. For instance, the
3066 following type declaration
3067
3068 @smallexample
3069 USE ISO_C_BINDING
3070 TYPE, BIND(C) :: myType
3071 INTEGER(C_INT) :: i1, i2
3072 INTEGER(C_SIGNED_CHAR) :: i3
3073 REAL(C_DOUBLE) :: d1
3074 COMPLEX(C_FLOAT_COMPLEX) :: c1
3075 CHARACTER(KIND=C_CHAR) :: str(5)
3076 END TYPE
3077 @end smallexample
3078
3079 matches the following @code{struct} declaration in C
3080
3081 @smallexample
3082 struct @{
3083 int i1, i2;
3084 /* Note: "char" might be signed or unsigned. */
3085 signed char i3;
3086 double d1;
3087 float _Complex c1;
3088 char str[5];
3089 @} myType;
3090 @end smallexample
3091
3092 Derived types with the C binding attribute shall not have the @code{sequence}
3093 attribute, type parameters, the @code{extends} attribute, nor type-bound
3094 procedures. Every component must be of interoperable type and kind and may not
3095 have the @code{pointer} or @code{allocatable} attribute. The names of the
3096 components are irrelevant for interoperability.
3097
3098 As there exist no direct Fortran equivalents, neither unions nor structs
3099 with bit field or variable-length array members are interoperable.
3100
3101 @node Interoperable Global Variables
3102 @subsection Interoperable Global Variables
3103
3104 Variables can be made accessible from C using the C binding attribute,
3105 optionally together with specifying a binding name. Those variables
3106 have to be declared in the declaration part of a @code{MODULE},
3107 be of interoperable type, and have neither the @code{pointer} nor
3108 the @code{allocatable} attribute.
3109
3110 @smallexample
3111 MODULE m
3112 USE myType_module
3113 USE ISO_C_BINDING
3114 integer(C_INT), bind(C, name="_MyProject_flags") :: global_flag
3115 type(myType), bind(C) :: tp
3116 END MODULE
3117 @end smallexample
3118
3119 Here, @code{_MyProject_flags} is the case-sensitive name of the variable
3120 as seen from C programs while @code{global_flag} is the case-insensitive
3121 name as seen from Fortran. If no binding name is specified, as for
3122 @var{tp}, the C binding name is the (lowercase) Fortran binding name.
3123 If a binding name is specified, only a single variable may be after the
3124 double colon. Note of warning: You cannot use a global variable to
3125 access @var{errno} of the C library as the C standard allows it to be
3126 a macro. Use the @code{IERRNO} intrinsic (GNU extension) instead.
3127
3128 @node Interoperable Subroutines and Functions
3129 @subsection Interoperable Subroutines and Functions
3130
3131 Subroutines and functions have to have the @code{BIND(C)} attribute to
3132 be compatible with C. The dummy argument declaration is relatively
3133 straightforward. However, one needs to be careful because C uses
3134 call-by-value by default while Fortran behaves usually similar to
3135 call-by-reference. Furthermore, strings and pointers are handled
3136 differently. Note that in Fortran 2003 and 2008 only explicit size
3137 and assumed-size arrays are supported but not assumed-shape or
3138 deferred-shape (i.e. allocatable or pointer) arrays. However, those
3139 are allowed since the Technical Specification 29113, see
3140 @ref{Further Interoperability of Fortran with C}
3141
3142 To pass a variable by value, use the @code{VALUE} attribute.
3143 Thus, the following C prototype
3144
3145 @smallexample
3146 @code{int func(int i, int *j)}
3147 @end smallexample
3148
3149 matches the Fortran declaration
3150
3151 @smallexample
3152 integer(c_int) function func(i,j)
3153 use iso_c_binding, only: c_int
3154 integer(c_int), VALUE :: i
3155 integer(c_int) :: j
3156 @end smallexample
3157
3158 Note that pointer arguments also frequently need the @code{VALUE} attribute,
3159 see @ref{Working with Pointers}.
3160
3161 Strings are handled quite differently in C and Fortran. In C a string
3162 is a @code{NUL}-terminated array of characters while in Fortran each string
3163 has a length associated with it and is thus not terminated (by e.g.
3164 @code{NUL}). For example, if one wants to use the following C function,
3165
3166 @smallexample
3167 #include <stdio.h>
3168 void print_C(char *string) /* equivalent: char string[] */
3169 @{
3170 printf("%s\n", string);
3171 @}
3172 @end smallexample
3173
3174 to print ``Hello World'' from Fortran, one can call it using
3175
3176 @smallexample
3177 use iso_c_binding, only: C_CHAR, C_NULL_CHAR
3178 interface
3179 subroutine print_c(string) bind(C, name="print_C")
3180 use iso_c_binding, only: c_char
3181 character(kind=c_char) :: string(*)
3182 end subroutine print_c
3183 end interface
3184 call print_c(C_CHAR_"Hello World"//C_NULL_CHAR)
3185 @end smallexample
3186
3187 As the example shows, one needs to ensure that the
3188 string is @code{NUL} terminated. Additionally, the dummy argument
3189 @var{string} of @code{print_C} is a length-one assumed-size
3190 array; using @code{character(len=*)} is not allowed. The example
3191 above uses @code{c_char_"Hello World"} to ensure the string
3192 literal has the right type; typically the default character
3193 kind and @code{c_char} are the same and thus @code{"Hello World"}
3194 is equivalent. However, the standard does not guarantee this.
3195
3196 The use of strings is now further illustrated using the C library
3197 function @code{strncpy}, whose prototype is
3198
3199 @smallexample
3200 char *strncpy(char *restrict s1, const char *restrict s2, size_t n);
3201 @end smallexample
3202
3203 The function @code{strncpy} copies at most @var{n} characters from
3204 string @var{s2} to @var{s1} and returns @var{s1}. In the following
3205 example, we ignore the return value:
3206
3207 @smallexample
3208 use iso_c_binding
3209 implicit none
3210 character(len=30) :: str,str2
3211 interface
3212 ! Ignore the return value of strncpy -> subroutine
3213 ! "restrict" is always assumed if we do not pass a pointer
3214 subroutine strncpy(dest, src, n) bind(C)
3215 import
3216 character(kind=c_char), intent(out) :: dest(*)
3217 character(kind=c_char), intent(in) :: src(*)
3218 integer(c_size_t), value, intent(in) :: n
3219 end subroutine strncpy
3220 end interface
3221 str = repeat('X',30) ! Initialize whole string with 'X'
3222 call strncpy(str, c_char_"Hello World"//C_NULL_CHAR, &
3223 len(c_char_"Hello World",kind=c_size_t))
3224 print '(a)', str ! prints: "Hello WorldXXXXXXXXXXXXXXXXXXX"
3225 end
3226 @end smallexample
3227
3228 The intrinsic procedures are described in @ref{Intrinsic Procedures}.
3229
3230 @node Working with Pointers
3231 @subsection Working with Pointers
3232
3233 C pointers are represented in Fortran via the special opaque derived type
3234 @code{type(c_ptr)} (with private components). Thus one needs to
3235 use intrinsic conversion procedures to convert from or to C pointers.
3236
3237 For some applications, using an assumed type (@code{TYPE(*)}) can be an
3238 alternative to a C pointer; see
3239 @ref{Further Interoperability of Fortran with C}.
3240
3241 For example,
3242
3243 @smallexample
3244 use iso_c_binding
3245 type(c_ptr) :: cptr1, cptr2
3246 integer, target :: array(7), scalar
3247 integer, pointer :: pa(:), ps
3248 cptr1 = c_loc(array(1)) ! The programmer needs to ensure that the
3249 ! array is contiguous if required by the C
3250 ! procedure
3251 cptr2 = c_loc(scalar)
3252 call c_f_pointer(cptr2, ps)
3253 call c_f_pointer(cptr2, pa, shape=[7])
3254 @end smallexample
3255
3256 When converting C to Fortran arrays, the one-dimensional @code{SHAPE} argument
3257 has to be passed.
3258
3259 If a pointer is a dummy-argument of an interoperable procedure, it usually
3260 has to be declared using the @code{VALUE} attribute. @code{void*}
3261 matches @code{TYPE(C_PTR), VALUE}, while @code{TYPE(C_PTR)} alone
3262 matches @code{void**}.
3263
3264 Procedure pointers are handled analogously to pointers; the C type is
3265 @code{TYPE(C_FUNPTR)} and the intrinsic conversion procedures are
3266 @code{C_F_PROCPOINTER} and @code{C_FUNLOC}.
3267
3268 Let us consider two examples of actually passing a procedure pointer from
3269 C to Fortran and vice versa. Note that these examples are also very
3270 similar to passing ordinary pointers between both languages. First,
3271 consider this code in C:
3272
3273 @smallexample
3274 /* Procedure implemented in Fortran. */
3275 void get_values (void (*)(double));
3276
3277 /* Call-back routine we want called from Fortran. */
3278 void
3279 print_it (double x)
3280 @{
3281 printf ("Number is %f.\n", x);
3282 @}
3283
3284 /* Call Fortran routine and pass call-back to it. */
3285 void
3286 foobar ()
3287 @{
3288 get_values (&print_it);
3289 @}
3290 @end smallexample
3291
3292 A matching implementation for @code{get_values} in Fortran, that correctly
3293 receives the procedure pointer from C and is able to call it, is given
3294 in the following @code{MODULE}:
3295
3296 @smallexample
3297 MODULE m
3298 IMPLICIT NONE
3299
3300 ! Define interface of call-back routine.
3301 ABSTRACT INTERFACE
3302 SUBROUTINE callback (x)
3303 USE, INTRINSIC :: ISO_C_BINDING
3304 REAL(KIND=C_DOUBLE), INTENT(IN), VALUE :: x
3305 END SUBROUTINE callback
3306 END INTERFACE
3307
3308 CONTAINS
3309
3310 ! Define C-bound procedure.
3311 SUBROUTINE get_values (cproc) BIND(C)
3312 USE, INTRINSIC :: ISO_C_BINDING
3313 TYPE(C_FUNPTR), INTENT(IN), VALUE :: cproc
3314
3315 PROCEDURE(callback), POINTER :: proc
3316
3317 ! Convert C to Fortran procedure pointer.
3318 CALL C_F_PROCPOINTER (cproc, proc)
3319
3320 ! Call it.
3321 CALL proc (1.0_C_DOUBLE)
3322 CALL proc (-42.0_C_DOUBLE)
3323 CALL proc (18.12_C_DOUBLE)
3324 END SUBROUTINE get_values
3325
3326 END MODULE m
3327 @end smallexample
3328
3329 Next, we want to call a C routine that expects a procedure pointer argument
3330 and pass it a Fortran procedure (which clearly must be interoperable!).
3331 Again, the C function may be:
3332
3333 @smallexample
3334 int
3335 call_it (int (*func)(int), int arg)
3336 @{
3337 return func (arg);
3338 @}
3339 @end smallexample
3340
3341 It can be used as in the following Fortran code:
3342
3343 @smallexample
3344 MODULE m
3345 USE, INTRINSIC :: ISO_C_BINDING
3346 IMPLICIT NONE
3347
3348 ! Define interface of C function.
3349 INTERFACE
3350 INTEGER(KIND=C_INT) FUNCTION call_it (func, arg) BIND(C)
3351 USE, INTRINSIC :: ISO_C_BINDING
3352 TYPE(C_FUNPTR), INTENT(IN), VALUE :: func
3353 INTEGER(KIND=C_INT), INTENT(IN), VALUE :: arg
3354 END FUNCTION call_it
3355 END INTERFACE
3356
3357 CONTAINS
3358
3359 ! Define procedure passed to C function.
3360 ! It must be interoperable!
3361 INTEGER(KIND=C_INT) FUNCTION double_it (arg) BIND(C)
3362 INTEGER(KIND=C_INT), INTENT(IN), VALUE :: arg
3363 double_it = arg + arg
3364 END FUNCTION double_it
3365
3366 ! Call C function.
3367 SUBROUTINE foobar ()
3368 TYPE(C_FUNPTR) :: cproc
3369 INTEGER(KIND=C_INT) :: i
3370
3371 ! Get C procedure pointer.
3372 cproc = C_FUNLOC (double_it)
3373
3374 ! Use it.
3375 DO i = 1_C_INT, 10_C_INT
3376 PRINT *, call_it (cproc, i)
3377 END DO
3378 END SUBROUTINE foobar
3379
3380 END MODULE m
3381 @end smallexample
3382
3383 @node Further Interoperability of Fortran with C
3384 @subsection Further Interoperability of Fortran with C
3385
3386 The Technical Specification ISO/IEC TS 29113:2012 on further
3387 interoperability of Fortran with C extends the interoperability support
3388 of Fortran 2003 and Fortran 2008. Besides removing some restrictions
3389 and constraints, it adds assumed-type (@code{TYPE(*)}) and assumed-rank
3390 (@code{dimension}) variables and allows for interoperability of
3391 assumed-shape, assumed-rank and deferred-shape arrays, including
3392 allocatables and pointers.
3393
3394 Note: Currently, GNU Fortran does not support the array descriptor
3395 (dope vector) as specified in the Technical Specification, but uses
3396 an array descriptor with different fields. The Chasm Language
3397 Interoperability Tools, @url{http://chasm-interop.sourceforge.net/},
3398 provide an interface to GNU Fortran's array descriptor.
3399
3400 The Technical Specification adds the following new features, which
3401 are supported by GNU Fortran:
3402
3403 @itemize @bullet
3404
3405 @item The @code{ASYNCHRONOUS} attribute has been clarified and
3406 extended to allow its use with asynchronous communication in
3407 user-provided libraries such as in implementations of the
3408 Message Passing Interface specification.
3409
3410 @item Many constraints have been relaxed, in particular for
3411 the @code{C_LOC} and @code{C_F_POINTER} intrinsics.
3412
3413 @item The @code{OPTIONAL} attribute is now allowed for dummy
3414 arguments; an absent argument matches a @code{NULL} pointer.
3415
3416 @item Assumed types (@code{TYPE(*)}) have been added, which may
3417 only be used for dummy arguments. They are unlimited polymorphic
3418 but contrary to @code{CLASS(*)} they do not contain any type
3419 information, similar to C's @code{void *} pointers. Expressions
3420 of any type and kind can be passed; thus, it can be used as
3421 replacement for @code{TYPE(C_PTR)}, avoiding the use of
3422 @code{C_LOC} in the caller.
3423
3424 Note, however, that @code{TYPE(*)} only accepts scalar arguments,
3425 unless the @code{DIMENSION} is explicitly specified. As
3426 @code{DIMENSION(*)} only supports array (including array elements) but
3427 no scalars, it is not a full replacement for @code{C_LOC}. On the
3428 other hand, assumed-type assumed-rank dummy arguments
3429 (@code{TYPE(*), DIMENSION(..)}) allow for both scalars and arrays, but
3430 require special code on the callee side to handle the array descriptor.
3431
3432 @item Assumed-rank arrays (@code{DIMENSION(..)}) as dummy argument
3433 allow that scalars and arrays of any rank can be passed as actual
3434 argument. As the Technical Specification does not provide for direct
3435 means to operate with them, they have to be used either from the C side
3436 or be converted using @code{C_LOC} and @code{C_F_POINTER} to scalars
3437 or arrays of a specific rank. The rank can be determined using the
3438 @code{RANK} intrinisic.
3439 @end itemize
3440
3441
3442 Currently unimplemented:
3443
3444 @itemize @bullet
3445
3446 @item GNU Fortran always uses an array descriptor, which does not
3447 match the one of the Technical Specification. The
3448 @code{ISO_Fortran_binding.h} header file and the C functions it
3449 specifies are not available.
3450
3451 @item Using assumed-shape, assumed-rank and deferred-shape arrays in
3452 @code{BIND(C)} procedures is not fully supported. In particular,
3453 C interoperable strings of other length than one are not supported
3454 as this requires the new array descriptor.
3455 @end itemize
3456
3457
3458 @node GNU Fortran Compiler Directives
3459 @section GNU Fortran Compiler Directives
3460
3461 @menu
3462 * ATTRIBUTES directive::
3463 * UNROLL directive::
3464 @end menu
3465
3466 @node ATTRIBUTES directive
3467 @subsection ATTRIBUTES directive
3468
3469 The Fortran standard describes how a conforming program shall
3470 behave; however, the exact implementation is not standardized. In order
3471 to allow the user to choose specific implementation details, compiler
3472 directives can be used to set attributes of variables and procedures
3473 which are not part of the standard. Whether a given attribute is
3474 supported and its exact effects depend on both the operating system and
3475 on the processor; see
3476 @ref{Top,,C Extensions,gcc,Using the GNU Compiler Collection (GCC)}
3477 for details.
3478
3479 For procedures and procedure pointers, the following attributes can
3480 be used to change the calling convention:
3481
3482 @itemize
3483 @item @code{CDECL} -- standard C calling convention
3484 @item @code{STDCALL} -- convention where the called procedure pops the stack
3485 @item @code{FASTCALL} -- part of the arguments are passed via registers
3486 instead using the stack
3487 @end itemize
3488
3489 Besides changing the calling convention, the attributes also influence
3490 the decoration of the symbol name, e.g., by a leading underscore or by
3491 a trailing at-sign followed by the number of bytes on the stack. When
3492 assigning a procedure to a procedure pointer, both should use the same
3493 calling convention.
3494
3495 On some systems, procedures and global variables (module variables and
3496 @code{COMMON} blocks) need special handling to be accessible when they
3497 are in a shared library. The following attributes are available:
3498
3499 @itemize
3500 @item @code{DLLEXPORT} -- provide a global pointer to a pointer in the DLL
3501 @item @code{DLLIMPORT} -- reference the function or variable using a
3502 global pointer
3503 @end itemize
3504
3505 For dummy arguments, the @code{NO_ARG_CHECK} attribute can be used; in
3506 other compilers, it is also known as @code{IGNORE_TKR}. For dummy arguments
3507 with this attribute actual arguments of any type and kind (similar to
3508 @code{TYPE(*)}), scalars and arrays of any rank (no equivalent
3509 in Fortran standard) are accepted. As with @code{TYPE(*)}, the argument
3510 is unlimited polymorphic and no type information is available.
3511 Additionally, the argument may only be passed to dummy arguments
3512 with the @code{NO_ARG_CHECK} attribute and as argument to the
3513 @code{PRESENT} intrinsic function and to @code{C_LOC} of the
3514 @code{ISO_C_BINDING} module.
3515
3516 Variables with @code{NO_ARG_CHECK} attribute shall be of assumed-type
3517 (@code{TYPE(*)}; recommended) or of type @code{INTEGER}, @code{LOGICAL},
3518 @code{REAL} or @code{COMPLEX}. They shall not have the @code{ALLOCATE},
3519 @code{CODIMENSION}, @code{INTENT(OUT)}, @code{POINTER} or @code{VALUE}
3520 attribute; furthermore, they shall be either scalar or of assumed-size
3521 (@code{dimension(*)}). As @code{TYPE(*)}, the @code{NO_ARG_CHECK} attribute
3522 requires an explicit interface.
3523
3524 @itemize
3525 @item @code{NO_ARG_CHECK} -- disable the type, kind and rank checking
3526 @end itemize
3527
3528
3529 The attributes are specified using the syntax
3530
3531 @code{!GCC$ ATTRIBUTES} @var{attribute-list} @code{::} @var{variable-list}
3532
3533 where in free-form source code only whitespace is allowed before @code{!GCC$}
3534 and in fixed-form source code @code{!GCC$}, @code{cGCC$} or @code{*GCC$} shall
3535 start in the first column.
3536
3537 For procedures, the compiler directives shall be placed into the body
3538 of the procedure; for variables and procedure pointers, they shall be in
3539 the same declaration part as the variable or procedure pointer.
3540
3541
3542 @node UNROLL directive
3543 @subsection UNROLL directive
3544
3545 The syntax of the directive is
3546
3547 @code{!GCC$ unroll N}
3548
3549 You can use this directive to control how many times a loop should be unrolled.
3550 It must be placed immediately before a @code{DO} loop and applies only to the
3551 loop that follows. N is an integer constant specifying the unrolling factor.
3552 The values of 0 and 1 block any unrolling of the loop.
3553
3554
3555
3556 @node Non-Fortran Main Program
3557 @section Non-Fortran Main Program
3558
3559 @menu
3560 * _gfortran_set_args:: Save command-line arguments
3561 * _gfortran_set_options:: Set library option flags
3562 * _gfortran_set_convert:: Set endian conversion
3563 * _gfortran_set_record_marker:: Set length of record markers
3564 * _gfortran_set_fpe:: Set when a Floating Point Exception should be raised
3565 * _gfortran_set_max_subrecord_length:: Set subrecord length
3566 @end menu
3567
3568 Even if you are doing mixed-language programming, it is very
3569 likely that you do not need to know or use the information in this
3570 section. Since it is about the internal structure of GNU Fortran,
3571 it may also change in GCC minor releases.
3572
3573 When you compile a @code{PROGRAM} with GNU Fortran, a function
3574 with the name @code{main} (in the symbol table of the object file)
3575 is generated, which initializes the libgfortran library and then
3576 calls the actual program which uses the name @code{MAIN__}, for
3577 historic reasons. If you link GNU Fortran compiled procedures
3578 to, e.g., a C or C++ program or to a Fortran program compiled by
3579 a different compiler, the libgfortran library is not initialized
3580 and thus a few intrinsic procedures do not work properly, e.g.
3581 those for obtaining the command-line arguments.
3582
3583 Therefore, if your @code{PROGRAM} is not compiled with
3584 GNU Fortran and the GNU Fortran compiled procedures require
3585 intrinsics relying on the library initialization, you need to
3586 initialize the library yourself. Using the default options,
3587 gfortran calls @code{_gfortran_set_args} and
3588 @code{_gfortran_set_options}. The initialization of the former
3589 is needed if the called procedures access the command line
3590 (and for backtracing); the latter sets some flags based on the
3591 standard chosen or to enable backtracing. In typical programs,
3592 it is not necessary to call any initialization function.
3593
3594 If your @code{PROGRAM} is compiled with GNU Fortran, you shall
3595 not call any of the following functions. The libgfortran
3596 initialization functions are shown in C syntax but using C
3597 bindings they are also accessible from Fortran.
3598
3599
3600 @node _gfortran_set_args
3601 @subsection @code{_gfortran_set_args} --- Save command-line arguments
3602 @fnindex _gfortran_set_args
3603 @cindex libgfortran initialization, set_args
3604
3605 @table @asis
3606 @item @emph{Description}:
3607 @code{_gfortran_set_args} saves the command-line arguments; this
3608 initialization is required if any of the command-line intrinsics
3609 is called. Additionally, it shall be called if backtracing is
3610 enabled (see @code{_gfortran_set_options}).
3611
3612 @item @emph{Syntax}:
3613 @code{void _gfortran_set_args (int argc, char *argv[])}
3614
3615 @item @emph{Arguments}:
3616 @multitable @columnfractions .15 .70
3617 @item @var{argc} @tab number of command line argument strings
3618 @item @var{argv} @tab the command-line argument strings; argv[0]
3619 is the pathname of the executable itself.
3620 @end multitable
3621
3622 @item @emph{Example}:
3623 @smallexample
3624 int main (int argc, char *argv[])
3625 @{
3626 /* Initialize libgfortran. */
3627 _gfortran_set_args (argc, argv);
3628 return 0;
3629 @}
3630 @end smallexample
3631 @end table
3632
3633
3634 @node _gfortran_set_options
3635 @subsection @code{_gfortran_set_options} --- Set library option flags
3636 @fnindex _gfortran_set_options
3637 @cindex libgfortran initialization, set_options
3638
3639 @table @asis
3640 @item @emph{Description}:
3641 @code{_gfortran_set_options} sets several flags related to the Fortran
3642 standard to be used, whether backtracing should be enabled
3643 and whether range checks should be performed. The syntax allows for
3644 upward compatibility since the number of passed flags is specified; for
3645 non-passed flags, the default value is used. See also
3646 @pxref{Code Gen Options}. Please note that not all flags are actually
3647 used.
3648
3649 @item @emph{Syntax}:
3650 @code{void _gfortran_set_options (int num, int options[])}
3651
3652 @item @emph{Arguments}:
3653 @multitable @columnfractions .15 .70
3654 @item @var{num} @tab number of options passed
3655 @item @var{argv} @tab The list of flag values
3656 @end multitable
3657
3658 @item @emph{option flag list}:
3659 @multitable @columnfractions .15 .70
3660 @item @var{option}[0] @tab Allowed standard; can give run-time errors
3661 if e.g. an input-output edit descriptor is invalid in a given
3662 standard. Possible values are (bitwise or-ed) @code{GFC_STD_F77} (1),
3663 @code{GFC_STD_F95_OBS} (2), @code{GFC_STD_F95_DEL} (4),
3664 @code{GFC_STD_F95} (8), @code{GFC_STD_F2003} (16), @code{GFC_STD_GNU}
3665 (32), @code{GFC_STD_LEGACY} (64), @code{GFC_STD_F2008} (128),
3666 @code{GFC_STD_F2008_OBS} (256), @code{GFC_STD_F2008_TS} (512),
3667 @code{GFC_STD_F2018} (1024), @code{GFC_STD_F2018_OBS} (2048), and
3668 @code{GFC_STD=F2018_DEL} (4096). Default: @code{GFC_STD_F95_OBS |
3669 GFC_STD_F95_DEL | GFC_STD_F95 | GFC_STD_F2003 | GFC_STD_F2008 |
3670 GFC_STD_F2008_TS | GFC_STD_F2008_OBS | GFC_STD_F77 | GFC_STD_F2018 |
3671 GFC_STD_F2018_OBS | GFC_STD_F2018_DEL | GFC_STD_GNU | GFC_STD_LEGACY}.
3672 @item @var{option}[1] @tab Standard-warning flag; prints a warning to
3673 standard error. Default: @code{GFC_STD_F95_DEL | GFC_STD_LEGACY}.
3674 @item @var{option}[2] @tab If non zero, enable pedantic checking.
3675 Default: off.
3676 @item @var{option}[3] @tab Unused.
3677 @item @var{option}[4] @tab If non zero, enable backtracing on run-time
3678 errors. Default: off. (Default in the compiler: on.)
3679 Note: Installs a signal handler and requires command-line
3680 initialization using @code{_gfortran_set_args}.
3681 @item @var{option}[5] @tab If non zero, supports signed zeros.
3682 Default: enabled.
3683 @item @var{option}[6] @tab Enables run-time checking. Possible values
3684 are (bitwise or-ed): GFC_RTCHECK_BOUNDS (1), GFC_RTCHECK_ARRAY_TEMPS (2),
3685 GFC_RTCHECK_RECURSION (4), GFC_RTCHECK_DO (16), GFC_RTCHECK_POINTER (32).
3686 Default: disabled.
3687 @item @var{option}[7] @tab Unused.
3688 @item @var{option}[8] @tab Show a warning when invoking @code{STOP} and
3689 @code{ERROR STOP} if a floating-point exception occurred. Possible values
3690 are (bitwise or-ed) @code{GFC_FPE_INVALID} (1), @code{GFC_FPE_DENORMAL} (2),
3691 @code{GFC_FPE_ZERO} (4), @code{GFC_FPE_OVERFLOW} (8),
3692 @code{GFC_FPE_UNDERFLOW} (16), @code{GFC_FPE_INEXACT} (32). Default: None (0).
3693 (Default in the compiler: @code{GFC_FPE_INVALID | GFC_FPE_DENORMAL |
3694 GFC_FPE_ZERO | GFC_FPE_OVERFLOW | GFC_FPE_UNDERFLOW}.)
3695 @end multitable
3696
3697 @item @emph{Example}:
3698 @smallexample
3699 /* Use gfortran 4.9 default options. */
3700 static int options[] = @{68, 511, 0, 0, 1, 1, 0, 0, 31@};
3701 _gfortran_set_options (9, &options);
3702 @end smallexample
3703 @end table
3704
3705
3706 @node _gfortran_set_convert
3707 @subsection @code{_gfortran_set_convert} --- Set endian conversion
3708 @fnindex _gfortran_set_convert
3709 @cindex libgfortran initialization, set_convert
3710
3711 @table @asis
3712 @item @emph{Description}:
3713 @code{_gfortran_set_convert} set the representation of data for
3714 unformatted files.
3715
3716 @item @emph{Syntax}:
3717 @code{void _gfortran_set_convert (int conv)}
3718
3719 @item @emph{Arguments}:
3720 @multitable @columnfractions .15 .70
3721 @item @var{conv} @tab Endian conversion, possible values:
3722 GFC_CONVERT_NATIVE (0, default), GFC_CONVERT_SWAP (1),
3723 GFC_CONVERT_BIG (2), GFC_CONVERT_LITTLE (3).
3724 @end multitable
3725
3726 @item @emph{Example}:
3727 @smallexample
3728 int main (int argc, char *argv[])
3729 @{
3730 /* Initialize libgfortran. */
3731 _gfortran_set_args (argc, argv);
3732 _gfortran_set_convert (1);
3733 return 0;
3734 @}
3735 @end smallexample
3736 @end table
3737
3738
3739 @node _gfortran_set_record_marker
3740 @subsection @code{_gfortran_set_record_marker} --- Set length of record markers
3741 @fnindex _gfortran_set_record_marker
3742 @cindex libgfortran initialization, set_record_marker
3743
3744 @table @asis
3745 @item @emph{Description}:
3746 @code{_gfortran_set_record_marker} sets the length of record markers
3747 for unformatted files.
3748
3749 @item @emph{Syntax}:
3750 @code{void _gfortran_set_record_marker (int val)}
3751
3752 @item @emph{Arguments}:
3753 @multitable @columnfractions .15 .70
3754 @item @var{val} @tab Length of the record marker; valid values
3755 are 4 and 8. Default is 4.
3756 @end multitable
3757
3758 @item @emph{Example}:
3759 @smallexample
3760 int main (int argc, char *argv[])
3761 @{
3762 /* Initialize libgfortran. */
3763 _gfortran_set_args (argc, argv);
3764 _gfortran_set_record_marker (8);
3765 return 0;
3766 @}
3767 @end smallexample
3768 @end table
3769
3770
3771 @node _gfortran_set_fpe
3772 @subsection @code{_gfortran_set_fpe} --- Enable floating point exception traps
3773 @fnindex _gfortran_set_fpe
3774 @cindex libgfortran initialization, set_fpe
3775
3776 @table @asis
3777 @item @emph{Description}:
3778 @code{_gfortran_set_fpe} enables floating point exception traps for
3779 the specified exceptions. On most systems, this will result in a
3780 SIGFPE signal being sent and the program being aborted.
3781
3782 @item @emph{Syntax}:
3783 @code{void _gfortran_set_fpe (int val)}
3784
3785 @item @emph{Arguments}:
3786 @multitable @columnfractions .15 .70
3787 @item @var{option}[0] @tab IEEE exceptions. Possible values are
3788 (bitwise or-ed) zero (0, default) no trapping,
3789 @code{GFC_FPE_INVALID} (1), @code{GFC_FPE_DENORMAL} (2),
3790 @code{GFC_FPE_ZERO} (4), @code{GFC_FPE_OVERFLOW} (8),
3791 @code{GFC_FPE_UNDERFLOW} (16), and @code{GFC_FPE_INEXACT} (32).
3792 @end multitable
3793
3794 @item @emph{Example}:
3795 @smallexample
3796 int main (int argc, char *argv[])
3797 @{
3798 /* Initialize libgfortran. */
3799 _gfortran_set_args (argc, argv);
3800 /* FPE for invalid operations such as SQRT(-1.0). */
3801 _gfortran_set_fpe (1);
3802 return 0;
3803 @}
3804 @end smallexample
3805 @end table
3806
3807
3808 @node _gfortran_set_max_subrecord_length
3809 @subsection @code{_gfortran_set_max_subrecord_length} --- Set subrecord length
3810 @fnindex _gfortran_set_max_subrecord_length
3811 @cindex libgfortran initialization, set_max_subrecord_length
3812
3813 @table @asis
3814 @item @emph{Description}:
3815 @code{_gfortran_set_max_subrecord_length} set the maximum length
3816 for a subrecord. This option only makes sense for testing and
3817 debugging of unformatted I/O.
3818
3819 @item @emph{Syntax}:
3820 @code{void _gfortran_set_max_subrecord_length (int val)}
3821
3822 @item @emph{Arguments}:
3823 @multitable @columnfractions .15 .70
3824 @item @var{val} @tab the maximum length for a subrecord;
3825 the maximum permitted value is 2147483639, which is also
3826 the default.
3827 @end multitable
3828
3829 @item @emph{Example}:
3830 @smallexample
3831 int main (int argc, char *argv[])
3832 @{
3833 /* Initialize libgfortran. */
3834 _gfortran_set_args (argc, argv);
3835 _gfortran_set_max_subrecord_length (8);
3836 return 0;
3837 @}
3838 @end smallexample
3839 @end table
3840
3841
3842 @node Naming and argument-passing conventions
3843 @section Naming and argument-passing conventions
3844
3845 This section gives an overview about the naming convention of procedures
3846 and global variables and about the argument passing conventions used by
3847 GNU Fortran. If a C binding has been specified, the naming convention
3848 and some of the argument-passing conventions change. If possible,
3849 mixed-language and mixed-compiler projects should use the better defined
3850 C binding for interoperability. See @pxref{Interoperability with C}.
3851
3852 @menu
3853 * Naming conventions::
3854 * Argument passing conventions::
3855 @end menu
3856
3857
3858 @node Naming conventions
3859 @subsection Naming conventions
3860
3861 According the Fortran standard, valid Fortran names consist of a letter
3862 between @code{A} to @code{Z}, @code{a} to @code{z}, digits @code{0},
3863 @code{1} to @code{9} and underscores (@code{_}) with the restriction
3864 that names may only start with a letter. As vendor extension, the
3865 dollar sign (@code{$}) is additionally permitted with the option
3866 @option{-fdollar-ok}, but not as first character and only if the
3867 target system supports it.
3868
3869 By default, the procedure name is the lower-cased Fortran name with an
3870 appended underscore (@code{_}); using @option{-fno-underscoring} no
3871 underscore is appended while @code{-fsecond-underscore} appends two
3872 underscores. Depending on the target system and the calling convention,
3873 the procedure might be additionally dressed; for instance, on 32bit
3874 Windows with @code{stdcall}, an at-sign @code{@@} followed by an integer
3875 number is appended. For the changing the calling convention, see
3876 @pxref{GNU Fortran Compiler Directives}.
3877
3878 For common blocks, the same convention is used, i.e. by default an
3879 underscore is appended to the lower-cased Fortran name. Blank commons
3880 have the name @code{__BLNK__}.
3881
3882 For procedures and variables declared in the specification space of a
3883 module, the name is formed by @code{__}, followed by the lower-cased
3884 module name, @code{_MOD_}, and the lower-cased Fortran name. Note that
3885 no underscore is appended.
3886
3887
3888 @node Argument passing conventions
3889 @subsection Argument passing conventions
3890
3891 Subroutines do not return a value (matching C99's @code{void}) while
3892 functions either return a value as specified in the platform ABI or
3893 the result variable is passed as hidden argument to the function and
3894 no result is returned. A hidden result variable is used when the
3895 result variable is an array or of type @code{CHARACTER}.
3896
3897 Arguments are passed according to the platform ABI. In particular,
3898 complex arguments might not be compatible to a struct with two real
3899 components for the real and imaginary part. The argument passing
3900 matches the one of C99's @code{_Complex}. Functions with scalar
3901 complex result variables return their value and do not use a
3902 by-reference argument. Note that with the @option{-ff2c} option,
3903 the argument passing is modified and no longer completely matches
3904 the platform ABI. Some other Fortran compilers use @code{f2c}
3905 semantic by default; this might cause problems with
3906 interoperablility.
3907
3908 GNU Fortran passes most arguments by reference, i.e. by passing a
3909 pointer to the data. Note that the compiler might use a temporary
3910 variable into which the actual argument has been copied, if required
3911 semantically (copy-in/copy-out).
3912
3913 For arguments with @code{ALLOCATABLE} and @code{POINTER}
3914 attribute (including procedure pointers), a pointer to the pointer
3915 is passed such that the pointer address can be modified in the
3916 procedure.
3917
3918 For dummy arguments with the @code{VALUE} attribute: Scalar arguments
3919 of the type @code{INTEGER}, @code{LOGICAL}, @code{REAL} and
3920 @code{COMPLEX} are passed by value according to the platform ABI.
3921 (As vendor extension and not recommended, using @code{%VAL()} in the
3922 call to a procedure has the same effect.) For @code{TYPE(C_PTR)} and
3923 procedure pointers, the pointer itself is passed such that it can be
3924 modified without affecting the caller.
3925 @c FIXME: Document how VALUE is handled for CHARACTER, TYPE,
3926 @c CLASS and arrays, i.e. whether the copy-in is done in the caller
3927 @c or in the callee.
3928
3929 For Boolean (@code{LOGICAL}) arguments, please note that GCC expects
3930 only the integer value 0 and 1. If a GNU Fortran @code{LOGICAL}
3931 variable contains another integer value, the result is undefined.
3932 As some other Fortran compilers use @math{-1} for @code{.TRUE.},
3933 extra care has to be taken -- such as passing the value as
3934 @code{INTEGER}. (The same value restriction also applies to other
3935 front ends of GCC, e.g. to GCC's C99 compiler for @code{_Bool}
3936 or GCC's Ada compiler for @code{Boolean}.)
3937
3938 For arguments of @code{CHARACTER} type, the character length is passed
3939 as a hidden argument at the end of the argument list. For
3940 deferred-length strings, the value is passed by reference, otherwise
3941 by value. The character length has the C type @code{size_t} (or
3942 @code{INTEGER(kind=C_SIZE_T)} in Fortran). Note that this is
3943 different to older versions of the GNU Fortran compiler, where the
3944 type of the hidden character length argument was a C @code{int}. In
3945 order to retain compatibility with older versions, one can e.g. for
3946 the following Fortran procedure
3947
3948 @smallexample
3949 subroutine fstrlen (s, a)
3950 character(len=*) :: s
3951 integer :: a
3952 print*, len(s)
3953 end subroutine fstrlen
3954 @end smallexample
3955
3956 define the corresponding C prototype as follows:
3957
3958 @smallexample
3959 #if __GNUC__ > 7
3960 typedef size_t fortran_charlen_t;
3961 #else
3962 typedef int fortran_charlen_t;
3963 #endif
3964
3965 void fstrlen_ (char*, int*, fortran_charlen_t);
3966 @end smallexample
3967
3968 In order to avoid such compiler-specific details, for new code it is
3969 instead recommended to use the ISO_C_BINDING feature.
3970
3971 Note with C binding, @code{CHARACTER(len=1)} result variables are
3972 returned according to the platform ABI and no hidden length argument
3973 is used for dummy arguments; with @code{VALUE}, those variables are
3974 passed by value.
3975
3976 For @code{OPTIONAL} dummy arguments, an absent argument is denoted
3977 by a NULL pointer, except for scalar dummy arguments of type
3978 @code{INTEGER}, @code{LOGICAL}, @code{REAL} and @code{COMPLEX}
3979 which have the @code{VALUE} attribute. For those, a hidden Boolean
3980 argument (@code{logical(kind=C_bool),value}) is used to indicate
3981 whether the argument is present.
3982
3983 Arguments which are assumed-shape, assumed-rank or deferred-rank
3984 arrays or, with @option{-fcoarray=lib}, allocatable scalar coarrays use
3985 an array descriptor. All other arrays pass the address of the
3986 first element of the array. With @option{-fcoarray=lib}, the token
3987 and the offset belonging to nonallocatable coarrays dummy arguments
3988 are passed as hidden argument along the character length hidden
3989 arguments. The token is an oparque pointer identifying the coarray
3990 and the offset is a passed-by-value integer of kind @code{C_PTRDIFF_T},
3991 denoting the byte offset between the base address of the coarray and
3992 the passed scalar or first element of the passed array.
3993
3994 The arguments are passed in the following order
3995 @itemize @bullet
3996 @item Result variable, when the function result is passed by reference
3997 @item Character length of the function result, if it is a of type
3998 @code{CHARACTER} and no C binding is used
3999 @item The arguments in the order in which they appear in the Fortran
4000 declaration
4001 @item The the present status for optional arguments with value attribute,
4002 which are internally passed by value
4003 @item The character length and/or coarray token and offset for the first
4004 argument which is a @code{CHARACTER} or a nonallocatable coarray dummy
4005 argument, followed by the hidden arguments of the next dummy argument
4006 of such a type
4007 @end itemize
4008
4009
4010 @c ---------------------------------------------------------------------
4011 @c Coarray Programming
4012 @c ---------------------------------------------------------------------
4013
4014 @node Coarray Programming
4015 @chapter Coarray Programming
4016 @cindex Coarrays
4017
4018 @menu
4019 * Type and enum ABI Documentation::
4020 * Function ABI Documentation::
4021 @end menu
4022
4023
4024 @node Type and enum ABI Documentation
4025 @section Type and enum ABI Documentation
4026
4027 @menu
4028 * caf_token_t::
4029 * caf_register_t::
4030 * caf_deregister_t::
4031 * caf_reference_t::
4032 * caf_team_t::
4033 @end menu
4034
4035 @node caf_token_t
4036 @subsection @code{caf_token_t}
4037
4038 Typedef of type @code{void *} on the compiler side. Can be any data
4039 type on the library side.
4040
4041 @node caf_register_t
4042 @subsection @code{caf_register_t}
4043
4044 Indicates which kind of coarray variable should be registered.
4045
4046 @verbatim
4047 typedef enum caf_register_t {
4048 CAF_REGTYPE_COARRAY_STATIC,
4049 CAF_REGTYPE_COARRAY_ALLOC,
4050 CAF_REGTYPE_LOCK_STATIC,
4051 CAF_REGTYPE_LOCK_ALLOC,
4052 CAF_REGTYPE_CRITICAL,
4053 CAF_REGTYPE_EVENT_STATIC,
4054 CAF_REGTYPE_EVENT_ALLOC,
4055 CAF_REGTYPE_COARRAY_ALLOC_REGISTER_ONLY,
4056 CAF_REGTYPE_COARRAY_ALLOC_ALLOCATE_ONLY
4057 }
4058 caf_register_t;
4059 @end verbatim
4060
4061 The values @code{CAF_REGTYPE_COARRAY_ALLOC_REGISTER_ONLY} and
4062 @code{CAF_REGTYPE_COARRAY_ALLOC_ALLOCATE_ONLY} are for allocatable components
4063 in derived type coarrays only. The first one sets up the token without
4064 allocating memory for allocatable component. The latter one only allocates the
4065 memory for an allocatable component in a derived type coarray. The token
4066 needs to be setup previously by the REGISTER_ONLY. This allows to have
4067 allocatable components un-allocated on some images. The status whether an
4068 allocatable component is allocated on a remote image can be queried by
4069 @code{_caf_is_present} which used internally by the @code{ALLOCATED}
4070 intrinsic.
4071
4072 @node caf_deregister_t
4073 @subsection @code{caf_deregister_t}
4074
4075 @verbatim
4076 typedef enum caf_deregister_t {
4077 CAF_DEREGTYPE_COARRAY_DEREGISTER,
4078 CAF_DEREGTYPE_COARRAY_DEALLOCATE_ONLY
4079 }
4080 caf_deregister_t;
4081 @end verbatim
4082
4083 Allows to specifiy the type of deregistration of a coarray object. The
4084 @code{CAF_DEREGTYPE_COARRAY_DEALLOCATE_ONLY} flag is only allowed for
4085 allocatable components in derived type coarrays.
4086
4087 @node caf_reference_t
4088 @subsection @code{caf_reference_t}
4089
4090 The structure used for implementing arbitrary reference chains.
4091 A @code{CAF_REFERENCE_T} allows to specify a component reference or any kind
4092 of array reference of any rank supported by gfortran. For array references all
4093 kinds as known by the compiler/Fortran standard are supported indicated by
4094 a @code{MODE}.
4095
4096 @verbatim
4097 typedef enum caf_ref_type_t {
4098 /* Reference a component of a derived type, either regular one or an
4099 allocatable or pointer type. For regular ones idx in caf_reference_t is
4100 set to -1. */
4101 CAF_REF_COMPONENT,
4102 /* Reference an allocatable array. */
4103 CAF_REF_ARRAY,
4104 /* Reference a non-allocatable/non-pointer array. I.e., the coarray object
4105 has no array descriptor associated and the addressing is done
4106 completely using the ref. */
4107 CAF_REF_STATIC_ARRAY
4108 } caf_ref_type_t;
4109 @end verbatim
4110
4111 @verbatim
4112 typedef enum caf_array_ref_t {
4113 /* No array ref. This terminates the array ref. */
4114 CAF_ARR_REF_NONE = 0,
4115 /* Reference array elements given by a vector. Only for this mode
4116 caf_reference_t.u.a.dim[i].v is valid. */
4117 CAF_ARR_REF_VECTOR,
4118 /* A full array ref (:). */
4119 CAF_ARR_REF_FULL,
4120 /* Reference a range on elements given by start, end and stride. */
4121 CAF_ARR_REF_RANGE,
4122 /* Only a single item is referenced given in the start member. */
4123 CAF_ARR_REF_SINGLE,
4124 /* An array ref of the kind (i:), where i is an arbitrary valid index in the
4125 array. The index i is given in the start member. */
4126 CAF_ARR_REF_OPEN_END,
4127 /* An array ref of the kind (:i), where the lower bound of the array ref
4128 is given by the remote side. The index i is given in the end member. */
4129 CAF_ARR_REF_OPEN_START
4130 } caf_array_ref_t;
4131 @end verbatim
4132
4133 @verbatim
4134 /* References to remote components of a derived type. */
4135 typedef struct caf_reference_t {
4136 /* A pointer to the next ref or NULL. */
4137 struct caf_reference_t *next;
4138 /* The type of the reference. */
4139 /* caf_ref_type_t, replaced by int to allow specification in fortran FE. */
4140 int type;
4141 /* The size of an item referenced in bytes. I.e. in an array ref this is
4142 the factor to advance the array pointer with to get to the next item.
4143 For component refs this gives just the size of the element referenced. */
4144 size_t item_size;
4145 union {
4146 struct {
4147 /* The offset (in bytes) of the component in the derived type.
4148 Unused for allocatable or pointer components. */
4149 ptrdiff_t offset;
4150 /* The offset (in bytes) to the caf_token associated with this
4151 component. NULL, when not allocatable/pointer ref. */
4152 ptrdiff_t caf_token_offset;
4153 } c;
4154 struct {
4155 /* The mode of the array ref. See CAF_ARR_REF_*. */
4156 /* caf_array_ref_t, replaced by unsigend char to allow specification in
4157 fortran FE. */
4158 unsigned char mode[GFC_MAX_DIMENSIONS];
4159 /* The type of a static array. Unset for array's with descriptors. */
4160 int static_array_type;
4161 /* Subscript refs (s) or vector refs (v). */
4162 union {
4163 struct {
4164 /* The start and end boundary of the ref and the stride. */
4165 index_type start, end, stride;
4166 } s;
4167 struct {
4168 /* nvec entries of kind giving the elements to reference. */
4169 void *vector;
4170 /* The number of entries in vector. */
4171 size_t nvec;
4172 /* The integer kind used for the elements in vector. */
4173 int kind;
4174 } v;
4175 } dim[GFC_MAX_DIMENSIONS];
4176 } a;
4177 } u;
4178 } caf_reference_t;
4179 @end verbatim
4180
4181 The references make up a single linked list of reference operations. The
4182 @code{NEXT} member links to the next reference or NULL to indicate the end of
4183 the chain. Component and array refs can be arbitrarly mixed as long as they
4184 comply to the Fortran standard.
4185
4186 @emph{NOTES}
4187 The member @code{STATIC_ARRAY_TYPE} is used only when the @code{TYPE} is
4188 @code{CAF_REF_STATIC_ARRAY}. The member gives the type of the data referenced.
4189 Because no array descriptor is available for a descriptor-less array and
4190 type conversion still needs to take place the type is transported here.
4191
4192 At the moment @code{CAF_ARR_REF_VECTOR} is not implemented in the front end for
4193 descriptor-less arrays. The library caf_single has untested support for it.
4194
4195 @node caf_team_t
4196 @subsection @code{caf_team_t}
4197
4198 Opaque pointer to represent a team-handle. This type is a stand-in for the
4199 future implementation of teams. It is about to change without further notice.
4200
4201 @node Function ABI Documentation
4202 @section Function ABI Documentation
4203
4204 @menu
4205 * _gfortran_caf_init:: Initialiation function
4206 * _gfortran_caf_finish:: Finalization function
4207 * _gfortran_caf_this_image:: Querying the image number
4208 * _gfortran_caf_num_images:: Querying the maximal number of images
4209 * _gfortran_caf_image_status :: Query the status of an image
4210 * _gfortran_caf_failed_images :: Get an array of the indexes of the failed images
4211 * _gfortran_caf_stopped_images :: Get an array of the indexes of the stopped images
4212 * _gfortran_caf_register:: Registering coarrays
4213 * _gfortran_caf_deregister:: Deregistering coarrays
4214 * _gfortran_caf_is_present:: Query whether an allocatable or pointer component in a derived type coarray is allocated
4215 * _gfortran_caf_send:: Sending data from a local image to a remote image
4216 * _gfortran_caf_get:: Getting data from a remote image
4217 * _gfortran_caf_sendget:: Sending data between remote images
4218 * _gfortran_caf_send_by_ref:: Sending data from a local image to a remote image using enhanced references
4219 * _gfortran_caf_get_by_ref:: Getting data from a remote image using enhanced references
4220 * _gfortran_caf_sendget_by_ref:: Sending data between remote images using enhanced references
4221 * _gfortran_caf_lock:: Locking a lock variable
4222 * _gfortran_caf_unlock:: Unlocking a lock variable
4223 * _gfortran_caf_event_post:: Post an event
4224 * _gfortran_caf_event_wait:: Wait that an event occurred
4225 * _gfortran_caf_event_query:: Query event count
4226 * _gfortran_caf_sync_all:: All-image barrier
4227 * _gfortran_caf_sync_images:: Barrier for selected images
4228 * _gfortran_caf_sync_memory:: Wait for completion of segment-memory operations
4229 * _gfortran_caf_error_stop:: Error termination with exit code
4230 * _gfortran_caf_error_stop_str:: Error termination with string
4231 * _gfortran_caf_fail_image :: Mark the image failed and end its execution
4232 * _gfortran_caf_atomic_define:: Atomic variable assignment
4233 * _gfortran_caf_atomic_ref:: Atomic variable reference
4234 * _gfortran_caf_atomic_cas:: Atomic compare and swap
4235 * _gfortran_caf_atomic_op:: Atomic operation
4236 * _gfortran_caf_co_broadcast:: Sending data to all images
4237 * _gfortran_caf_co_max:: Collective maximum reduction
4238 * _gfortran_caf_co_min:: Collective minimum reduction
4239 * _gfortran_caf_co_sum:: Collective summing reduction
4240 * _gfortran_caf_co_reduce:: Generic collective reduction
4241 @end menu
4242
4243
4244 @node _gfortran_caf_init
4245 @subsection @code{_gfortran_caf_init} --- Initialiation function
4246 @cindex Coarray, _gfortran_caf_init
4247
4248 @table @asis
4249 @item @emph{Description}:
4250 This function is called at startup of the program before the Fortran main
4251 program, if the latter has been compiled with @option{-fcoarray=lib}.
4252 It takes as arguments the command-line arguments of the program. It is
4253 permitted to pass two @code{NULL} pointers as argument; if non-@code{NULL},
4254 the library is permitted to modify the arguments.
4255
4256 @item @emph{Syntax}:
4257 @code{void _gfortran_caf_init (int *argc, char ***argv)}
4258
4259 @item @emph{Arguments}:
4260 @multitable @columnfractions .15 .70
4261 @item @var{argc} @tab intent(inout) An integer pointer with the number of
4262 arguments passed to the program or @code{NULL}.
4263 @item @var{argv} @tab intent(inout) A pointer to an array of strings with the
4264 command-line arguments or @code{NULL}.
4265 @end multitable
4266
4267 @item @emph{NOTES}
4268 The function is modelled after the initialization function of the Message
4269 Passing Interface (MPI) specification. Due to the way coarray registration
4270 works, it might not be the first call to the library. If the main program is
4271 not written in Fortran and only a library uses coarrays, it can happen that
4272 this function is never called. Therefore, it is recommended that the library
4273 does not rely on the passed arguments and whether the call has been done.
4274 @end table
4275
4276
4277 @node _gfortran_caf_finish
4278 @subsection @code{_gfortran_caf_finish} --- Finalization function
4279 @cindex Coarray, _gfortran_caf_finish
4280
4281 @table @asis
4282 @item @emph{Description}:
4283 This function is called at the end of the Fortran main program, if it has
4284 been compiled with the @option{-fcoarray=lib} option.
4285
4286 @item @emph{Syntax}:
4287 @code{void _gfortran_caf_finish (void)}
4288
4289 @item @emph{NOTES}
4290 For non-Fortran programs, it is recommended to call the function at the end
4291 of the main program. To ensure that the shutdown is also performed for
4292 programs where this function is not explicitly invoked, for instance
4293 non-Fortran programs or calls to the system's exit() function, the library
4294 can use a destructor function. Note that programs can also be terminated
4295 using the STOP and ERROR STOP statements; those use different library calls.
4296 @end table
4297
4298
4299 @node _gfortran_caf_this_image
4300 @subsection @code{_gfortran_caf_this_image} --- Querying the image number
4301 @cindex Coarray, _gfortran_caf_this_image
4302
4303 @table @asis
4304 @item @emph{Description}:
4305 This function returns the current image number, which is a positive number.
4306
4307 @item @emph{Syntax}:
4308 @code{int _gfortran_caf_this_image (int distance)}
4309
4310 @item @emph{Arguments}:
4311 @multitable @columnfractions .15 .70
4312 @item @var{distance} @tab As specified for the @code{this_image} intrinsic
4313 in TS18508. Shall be a non-negative number.
4314 @end multitable
4315
4316 @item @emph{NOTES}
4317 If the Fortran intrinsic @code{this_image} is invoked without an argument, which
4318 is the only permitted form in Fortran 2008, GCC passes @code{0} as
4319 first argument.
4320 @end table
4321
4322
4323 @node _gfortran_caf_num_images
4324 @subsection @code{_gfortran_caf_num_images} --- Querying the maximal number of images
4325 @cindex Coarray, _gfortran_caf_num_images
4326
4327 @table @asis
4328 @item @emph{Description}:
4329 This function returns the number of images in the current team, if
4330 @var{distance} is 0 or the number of images in the parent team at the specified
4331 distance. If failed is -1, the function returns the number of all images at
4332 the specified distance; if it is 0, the function returns the number of
4333 nonfailed images, and if it is 1, it returns the number of failed images.
4334
4335 @item @emph{Syntax}:
4336 @code{int _gfortran_caf_num_images(int distance, int failed)}
4337
4338 @item @emph{Arguments}:
4339 @multitable @columnfractions .15 .70
4340 @item @var{distance} @tab the distance from this image to the ancestor.
4341 Shall be positive.
4342 @item @var{failed} @tab shall be -1, 0, or 1
4343 @end multitable
4344
4345 @item @emph{NOTES}
4346 This function follows TS18508. If the num_image intrinsic has no arguments,
4347 then the compiler passes @code{distance=0} and @code{failed=-1} to the function.
4348 @end table
4349
4350
4351 @node _gfortran_caf_image_status
4352 @subsection @code{_gfortran_caf_image_status} --- Query the status of an image
4353 @cindex Coarray, _gfortran_caf_image_status
4354
4355 @table @asis
4356 @item @emph{Description}:
4357 Get the status of the image given by the id @var{image} of the team given by
4358 @var{team}. Valid results are zero, for image is ok, @code{STAT_STOPPED_IMAGE}
4359 from the ISO_FORTRAN_ENV module to indicate that the image has been stopped and
4360 @code{STAT_FAILED_IMAGE} also from ISO_FORTRAN_ENV to indicate that the image
4361 has executed a @code{FAIL IMAGE} statement.
4362
4363 @item @emph{Syntax}:
4364 @code{int _gfortran_caf_image_status (int image, caf_team_t * team)}
4365
4366 @item @emph{Arguments}:
4367 @multitable @columnfractions .15 .70
4368 @item @var{image} @tab the positive scalar id of the image in the current TEAM.
4369 @item @var{team} @tab optional; team on the which the inquiry is to be
4370 performed.
4371 @end multitable
4372
4373 @item @emph{NOTES}
4374 This function follows TS18508. Because team-functionality is not yet
4375 implemented a null-pointer is passed for the @var{team} argument at the moment.
4376 @end table
4377
4378
4379 @node _gfortran_caf_failed_images
4380 @subsection @code{_gfortran_caf_failed_images} --- Get an array of the indexes of the failed images
4381 @cindex Coarray, _gfortran_caf_failed_images
4382
4383 @table @asis
4384 @item @emph{Description}:
4385 Get an array of image indexes in the current @var{team} that have failed. The
4386 array is sorted ascendingly. When @var{team} is not provided the current team
4387 is to be used. When @var{kind} is provided then the resulting array is of that
4388 integer kind else it is of default integer kind. The returns an unallocated
4389 size zero array when no images have failed.
4390
4391 @item @emph{Syntax}:
4392 @code{int _gfortran_caf_failed_images (caf_team_t * team, int * kind)}
4393
4394 @item @emph{Arguments}:
4395 @multitable @columnfractions .15 .70
4396 @item @var{team} @tab optional; team on the which the inquiry is to be
4397 performed.
4398 @item @var{image} @tab optional; the kind of the resulting integer array.
4399 @end multitable
4400
4401 @item @emph{NOTES}
4402 This function follows TS18508. Because team-functionality is not yet
4403 implemented a null-pointer is passed for the @var{team} argument at the moment.
4404 @end table
4405
4406
4407 @node _gfortran_caf_stopped_images
4408 @subsection @code{_gfortran_caf_stopped_images} --- Get an array of the indexes of the stopped images
4409 @cindex Coarray, _gfortran_caf_stopped_images
4410
4411 @table @asis
4412 @item @emph{Description}:
4413 Get an array of image indexes in the current @var{team} that have stopped. The
4414 array is sorted ascendingly. When @var{team} is not provided the current team
4415 is to be used. When @var{kind} is provided then the resulting array is of that
4416 integer kind else it is of default integer kind. The returns an unallocated
4417 size zero array when no images have failed.
4418
4419 @item @emph{Syntax}:
4420 @code{int _gfortran_caf_stopped_images (caf_team_t * team, int * kind)}
4421
4422 @item @emph{Arguments}:
4423 @multitable @columnfractions .15 .70
4424 @item @var{team} @tab optional; team on the which the inquiry is to be
4425 performed.
4426 @item @var{image} @tab optional; the kind of the resulting integer array.
4427 @end multitable
4428
4429 @item @emph{NOTES}
4430 This function follows TS18508. Because team-functionality is not yet
4431 implemented a null-pointer is passed for the @var{team} argument at the moment.
4432 @end table
4433
4434
4435 @node _gfortran_caf_register
4436 @subsection @code{_gfortran_caf_register} --- Registering coarrays
4437 @cindex Coarray, _gfortran_caf_register
4438
4439 @table @asis
4440 @item @emph{Description}:
4441 Registers memory for a coarray and creates a token to identify the coarray. The
4442 routine is called for both coarrays with @code{SAVE} attribute and using an
4443 explicit @code{ALLOCATE} statement. If an error occurs and @var{STAT} is a
4444 @code{NULL} pointer, the function shall abort with printing an error message
4445 and starting the error termination. If no error occurs and @var{STAT} is
4446 present, it shall be set to zero. Otherwise, it shall be set to a positive
4447 value and, if not-@code{NULL}, @var{ERRMSG} shall be set to a string describing
4448 the failure. The routine shall register the memory provided in the
4449 @code{DATA}-component of the array descriptor @var{DESC}, when that component
4450 is non-@code{NULL}, else it shall allocate sufficient memory and provide a
4451 pointer to it in the @code{DATA}-component of @var{DESC}. The array descriptor
4452 has rank zero, when a scalar object is to be registered and the array
4453 descriptor may be invalid after the call to @code{_gfortran_caf_register}.
4454 When an array is to be allocated the descriptor persists.
4455
4456 For @code{CAF_REGTYPE_COARRAY_STATIC} and @code{CAF_REGTYPE_COARRAY_ALLOC},
4457 the passed size is the byte size requested. For @code{CAF_REGTYPE_LOCK_STATIC},
4458 @code{CAF_REGTYPE_LOCK_ALLOC} and @code{CAF_REGTYPE_CRITICAL} it is the array
4459 size or one for a scalar.
4460
4461 When @code{CAF_REGTYPE_COARRAY_ALLOC_REGISTER_ONLY} is used, then only a token
4462 for an allocatable or pointer component is created. The @code{SIZE} parameter
4463 is not used then. On the contrary when
4464 @code{CAF_REGTYPE_COARRAY_ALLOC_ALLOCATE_ONLY} is specified, then the
4465 @var{token} needs to be registered by a previous call with regtype
4466 @code{CAF_REGTYPE_COARRAY_ALLOC_REGISTER_ONLY} and either the memory specified
4467 in the @var{DESC}'s data-ptr is registered or allocate when the data-ptr is
4468 @code{NULL}.
4469
4470 @item @emph{Syntax}:
4471 @code{void caf_register (size_t size, caf_register_t type, caf_token_t *token,
4472 gfc_descriptor_t *desc, int *stat, char *errmsg, size_t errmsg_len)}
4473
4474 @item @emph{Arguments}:
4475 @multitable @columnfractions .15 .70
4476 @item @var{size} @tab For normal coarrays, the byte size of the coarray to be
4477 allocated; for lock types and event types, the number of elements.
4478 @item @var{type} @tab one of the caf_register_t types.
4479 @item @var{token} @tab intent(out) An opaque pointer identifying the coarray.
4480 @item @var{desc} @tab intent(inout) The (pseudo) array descriptor.
4481 @item @var{stat} @tab intent(out) For allocatable coarrays, stores the STAT=;
4482 may be @code{NULL}
4483 @item @var{errmsg} @tab intent(out) When an error occurs, this will be set to
4484 an error message; may be @code{NULL}
4485 @item @var{errmsg_len} @tab the buffer size of errmsg.
4486 @end multitable
4487
4488 @item @emph{NOTES}
4489 Nonallocatable coarrays have to be registered prior use from remote images.
4490 In order to guarantee this, they have to be registered before the main
4491 program. This can be achieved by creating constructor functions. That is what
4492 GCC does such that also for nonallocatable coarrays the memory is allocated and
4493 no static memory is used. The token permits to identify the coarray; to the
4494 processor, the token is a nonaliasing pointer. The library can, for instance,
4495 store the base address of the coarray in the token, some handle or a more
4496 complicated struct. The library may also store the array descriptor
4497 @var{DESC} when its rank is non-zero.
4498
4499 For lock types, the value shall only be used for checking the allocation
4500 status. Note that for critical blocks, the locking is only required on one
4501 image; in the locking statement, the processor shall always pass an
4502 image index of one for critical-block lock variables
4503 (@code{CAF_REGTYPE_CRITICAL}). For lock types and critical-block variables,
4504 the initial value shall be unlocked (or, respecitively, not in critical
4505 section) such as the value false; for event types, the initial state should
4506 be no event, e.g. zero.
4507 @end table
4508
4509
4510 @node _gfortran_caf_deregister
4511 @subsection @code{_gfortran_caf_deregister} --- Deregistering coarrays
4512 @cindex Coarray, _gfortran_caf_deregister
4513
4514 @table @asis
4515 @item @emph{Description}:
4516 Called to free or deregister the memory of a coarray; the processor calls this
4517 function for automatic and explicit deallocation. In case of an error, this
4518 function shall fail with an error message, unless the @var{STAT} variable is
4519 not null. The library is only expected to free memory it allocated itself
4520 during a call to @code{_gfortran_caf_register}.
4521
4522 @item @emph{Syntax}:
4523 @code{void caf_deregister (caf_token_t *token, caf_deregister_t type,
4524 int *stat, char *errmsg, size_t errmsg_len)}
4525
4526 @item @emph{Arguments}:
4527 @multitable @columnfractions .15 .70
4528 @item @var{token} @tab the token to free.
4529 @item @var{type} @tab the type of action to take for the coarray. A
4530 @code{CAF_DEREGTYPE_COARRAY_DEALLOCATE_ONLY} is allowed only for allocatable or
4531 pointer components of derived type coarrays. The action only deallocates the
4532 local memory without deleting the token.
4533 @item @var{stat} @tab intent(out) Stores the STAT=; may be NULL
4534 @item @var{errmsg} @tab intent(out) When an error occurs, this will be set
4535 to an error message; may be NULL
4536 @item @var{errmsg_len} @tab the buffer size of errmsg.
4537 @end multitable
4538
4539 @item @emph{NOTES}
4540 For nonalloatable coarrays this function is never called. If a cleanup is
4541 required, it has to be handled via the finish, stop and error stop functions,
4542 and via destructors.
4543 @end table
4544
4545
4546 @node _gfortran_caf_is_present
4547 @subsection @code{_gfortran_caf_is_present} --- Query whether an allocatable or pointer component in a derived type coarray is allocated
4548 @cindex Coarray, _gfortran_caf_is_present
4549
4550 @table @asis
4551 @item @emph{Description}:
4552 Used to query the coarray library whether an allocatable component in a derived
4553 type coarray is allocated on a remote image.
4554
4555 @item @emph{Syntax}:
4556 @code{void _gfortran_caf_is_present (caf_token_t token, int image_index,
4557 gfc_reference_t *ref)}
4558
4559 @item @emph{Arguments}:
4560 @multitable @columnfractions .15 .70
4561 @item @var{token} @tab An opaque pointer identifying the coarray.
4562 @item @var{image_index} @tab The ID of the remote image; must be a positive
4563 number.
4564 @item @var{ref} @tab A chain of references to address the allocatable or
4565 pointer component in the derived type coarray. The object reference needs to be
4566 a scalar or a full array reference, respectively.
4567 @end multitable
4568
4569 @end table
4570
4571 @node _gfortran_caf_send
4572 @subsection @code{_gfortran_caf_send} --- Sending data from a local image to a remote image
4573 @cindex Coarray, _gfortran_caf_send
4574
4575 @table @asis
4576 @item @emph{Description}:
4577 Called to send a scalar, an array section or a whole array from a local
4578 to a remote image identified by the image_index.
4579
4580 @item @emph{Syntax}:
4581 @code{void _gfortran_caf_send (caf_token_t token, size_t offset,
4582 int image_index, gfc_descriptor_t *dest, caf_vector_t *dst_vector,
4583 gfc_descriptor_t *src, int dst_kind, int src_kind, bool may_require_tmp,
4584 int *stat)}
4585
4586 @item @emph{Arguments}:
4587 @multitable @columnfractions .15 .70
4588 @item @var{token} @tab intent(in) An opaque pointer identifying the coarray.
4589 @item @var{offset} @tab intent(in) By which amount of bytes the actual data is
4590 shifted compared to the base address of the coarray.
4591 @item @var{image_index} @tab intent(in) The ID of the remote image; must be a
4592 positive number.
4593 @item @var{dest} @tab intent(in) Array descriptor for the remote image for the
4594 bounds and the size. The @code{base_addr} shall not be accessed.
4595 @item @var{dst_vector} @tab intent(in) If not NULL, it contains the vector
4596 subscript of the destination array; the values are relative to the dimension
4597 triplet of the dest argument.
4598 @item @var{src} @tab intent(in) Array descriptor of the local array to be
4599 transferred to the remote image
4600 @item @var{dst_kind} @tab intent(in) Kind of the destination argument
4601 @item @var{src_kind} @tab intent(in) Kind of the source argument
4602 @item @var{may_require_tmp} @tab intent(in) The variable is @code{false} when
4603 it is known at compile time that the @var{dest} and @var{src} either cannot
4604 overlap or overlap (fully or partially) such that walking @var{src} and
4605 @var{dest} in element wise element order (honoring the stride value) will not
4606 lead to wrong results. Otherwise, the value is @code{true}.
4607 @item @var{stat} @tab intent(out) when non-NULL give the result of the
4608 operation, i.e., zero on success and non-zero on error. When NULL and an error
4609 occurs, then an error message is printed and the program is terminated.
4610 @end multitable
4611
4612 @item @emph{NOTES}
4613 It is permitted to have @var{image_index} equal the current image; the memory
4614 of the send-to and the send-from might (partially) overlap in that case. The
4615 implementation has to take care that it handles this case, e.g. using
4616 @code{memmove} which handles (partially) overlapping memory. If
4617 @var{may_require_tmp} is true, the library might additionally create a
4618 temporary variable, unless additional checks show that this is not required
4619 (e.g. because walking backward is possible or because both arrays are
4620 contiguous and @code{memmove} takes care of overlap issues).
4621
4622 Note that the assignment of a scalar to an array is permitted. In addition,
4623 the library has to handle numeric-type conversion and for strings, padding
4624 and different character kinds.
4625 @end table
4626
4627
4628 @node _gfortran_caf_get
4629 @subsection @code{_gfortran_caf_get} --- Getting data from a remote image
4630 @cindex Coarray, _gfortran_caf_get
4631
4632 @table @asis
4633 @item @emph{Description}:
4634 Called to get an array section or a whole array from a remote,
4635 image identified by the image_index.
4636
4637 @item @emph{Syntax}:
4638 @code{void _gfortran_caf_get (caf_token_t token, size_t offset,
4639 int image_index, gfc_descriptor_t *src, caf_vector_t *src_vector,
4640 gfc_descriptor_t *dest, int src_kind, int dst_kind, bool may_require_tmp,
4641 int *stat)}
4642
4643 @item @emph{Arguments}:
4644 @multitable @columnfractions .15 .70
4645 @item @var{token} @tab intent(in) An opaque pointer identifying the coarray.
4646 @item @var{offset} @tab intent(in) By which amount of bytes the actual data is
4647 shifted compared to the base address of the coarray.
4648 @item @var{image_index} @tab intent(in) The ID of the remote image; must be a
4649 positive number.
4650 @item @var{dest} @tab intent(out) Array descriptor of the local array to store
4651 the data retrieved from the remote image
4652 @item @var{src} @tab intent(in) Array descriptor for the remote image for the
4653 bounds and the size. The @code{base_addr} shall not be accessed.
4654 @item @var{src_vector} @tab intent(in) If not NULL, it contains the vector
4655 subscript of the source array; the values are relative to the dimension
4656 triplet of the @var{src} argument.
4657 @item @var{dst_kind} @tab intent(in) Kind of the destination argument
4658 @item @var{src_kind} @tab intent(in) Kind of the source argument
4659 @item @var{may_require_tmp} @tab intent(in) The variable is @code{false} when
4660 it is known at compile time that the @var{dest} and @var{src} either cannot
4661 overlap or overlap (fully or partially) such that walking @var{src} and
4662 @var{dest} in element wise element order (honoring the stride value) will not
4663 lead to wrong results. Otherwise, the value is @code{true}.
4664 @item @var{stat} @tab intent(out) When non-NULL give the result of the
4665 operation, i.e., zero on success and non-zero on error. When NULL and an error
4666 occurs, then an error message is printed and the program is terminated.
4667 @end multitable
4668
4669 @item @emph{NOTES}
4670 It is permitted to have @var{image_index} equal the current image; the memory of
4671 the send-to and the send-from might (partially) overlap in that case. The
4672 implementation has to take care that it handles this case, e.g. using
4673 @code{memmove} which handles (partially) overlapping memory. If
4674 @var{may_require_tmp} is true, the library might additionally create a
4675 temporary variable, unless additional checks show that this is not required
4676 (e.g. because walking backward is possible or because both arrays are
4677 contiguous and @code{memmove} takes care of overlap issues).
4678
4679 Note that the library has to handle numeric-type conversion and for strings,
4680 padding and different character kinds.
4681 @end table
4682
4683
4684 @node _gfortran_caf_sendget
4685 @subsection @code{_gfortran_caf_sendget} --- Sending data between remote images
4686 @cindex Coarray, _gfortran_caf_sendget
4687
4688 @table @asis
4689 @item @emph{Description}:
4690 Called to send a scalar, an array section or a whole array from a remote image
4691 identified by the @var{src_image_index} to a remote image identified by the
4692 @var{dst_image_index}.
4693
4694 @item @emph{Syntax}:
4695 @code{void _gfortran_caf_sendget (caf_token_t dst_token, size_t dst_offset,
4696 int dst_image_index, gfc_descriptor_t *dest, caf_vector_t *dst_vector,
4697 caf_token_t src_token, size_t src_offset, int src_image_index,
4698 gfc_descriptor_t *src, caf_vector_t *src_vector, int dst_kind, int src_kind,
4699 bool may_require_tmp, int *stat)}
4700
4701 @item @emph{Arguments}:
4702 @multitable @columnfractions .15 .70
4703 @item @var{dst_token} @tab intent(in) An opaque pointer identifying the
4704 destination coarray.
4705 @item @var{dst_offset} @tab intent(in) By which amount of bytes the actual data
4706 is shifted compared to the base address of the destination coarray.
4707 @item @var{dst_image_index} @tab intent(in) The ID of the destination remote
4708 image; must be a positive number.
4709 @item @var{dest} @tab intent(in) Array descriptor for the destination
4710 remote image for the bounds and the size. The @code{base_addr} shall not be
4711 accessed.
4712 @item @var{dst_vector} @tab intent(int) If not NULL, it contains the vector
4713 subscript of the destination array; the values are relative to the dimension
4714 triplet of the @var{dest} argument.
4715 @item @var{src_token} @tab intent(in) An opaque pointer identifying the source
4716 coarray.
4717 @item @var{src_offset} @tab intent(in) By which amount of bytes the actual data
4718 is shifted compared to the base address of the source coarray.
4719 @item @var{src_image_index} @tab intent(in) The ID of the source remote image;
4720 must be a positive number.
4721 @item @var{src} @tab intent(in) Array descriptor of the local array to be
4722 transferred to the remote image.
4723 @item @var{src_vector} @tab intent(in) Array descriptor of the local array to
4724 be transferred to the remote image
4725 @item @var{dst_kind} @tab intent(in) Kind of the destination argument
4726 @item @var{src_kind} @tab intent(in) Kind of the source argument
4727 @item @var{may_require_tmp} @tab intent(in) The variable is @code{false} when
4728 it is known at compile time that the @var{dest} and @var{src} either cannot
4729 overlap or overlap (fully or partially) such that walking @var{src} and
4730 @var{dest} in element wise element order (honoring the stride value) will not
4731 lead to wrong results. Otherwise, the value is @code{true}.
4732 @item @var{stat} @tab intent(out) when non-NULL give the result of the
4733 operation, i.e., zero on success and non-zero on error. When NULL and an error
4734 occurs, then an error message is printed and the program is terminated.
4735 @end multitable
4736
4737 @item @emph{NOTES}
4738 It is permitted to have the same image index for both @var{src_image_index} and
4739 @var{dst_image_index}; the memory of the send-to and the send-from might
4740 (partially) overlap in that case. The implementation has to take care that it
4741 handles this case, e.g. using @code{memmove} which handles (partially)
4742 overlapping memory. If @var{may_require_tmp} is true, the library
4743 might additionally create a temporary variable, unless additional checks show
4744 that this is not required (e.g. because walking backward is possible or because
4745 both arrays are contiguous and @code{memmove} takes care of overlap issues).
4746
4747 Note that the assignment of a scalar to an array is permitted. In addition,
4748 the library has to handle numeric-type conversion and for strings, padding and
4749 different character kinds.
4750 @end table
4751
4752 @node _gfortran_caf_send_by_ref
4753 @subsection @code{_gfortran_caf_send_by_ref} --- Sending data from a local image to a remote image with enhanced referencing options
4754 @cindex Coarray, _gfortran_caf_send_by_ref
4755
4756 @table @asis
4757 @item @emph{Description}:
4758 Called to send a scalar, an array section or a whole array from a local to a
4759 remote image identified by the @var{image_index}.
4760
4761 @item @emph{Syntax}:
4762 @code{void _gfortran_caf_send_by_ref (caf_token_t token, int image_index,
4763 gfc_descriptor_t *src, caf_reference_t *refs, int dst_kind, int src_kind,
4764 bool may_require_tmp, bool dst_reallocatable, int *stat, int dst_type)}
4765
4766 @item @emph{Arguments}:
4767 @multitable @columnfractions .15 .70
4768 @item @var{token} @tab intent(in) An opaque pointer identifying the coarray.
4769 @item @var{image_index} @tab intent(in) The ID of the remote image; must be a
4770 positive number.
4771 @item @var{src} @tab intent(in) Array descriptor of the local array to be
4772 transferred to the remote image
4773 @item @var{refs} @tab intent(in) The references on the remote array to store
4774 the data given by src. Guaranteed to have at least one entry.
4775 @item @var{dst_kind} @tab intent(in) Kind of the destination argument
4776 @item @var{src_kind} @tab intent(in) Kind of the source argument
4777 @item @var{may_require_tmp} @tab intent(in) The variable is @code{false} when
4778 it is known at compile time that the @var{dest} and @var{src} either cannot
4779 overlap or overlap (fully or partially) such that walking @var{src} and
4780 @var{dest} in element wise element order (honoring the stride value) will not
4781 lead to wrong results. Otherwise, the value is @code{true}.
4782 @item @var{dst_reallocatable} @tab intent(in) Set when the destination is of
4783 allocatable or pointer type and the refs will allow reallocation, i.e., the ref
4784 is a full array or component ref.
4785 @item @var{stat} @tab intent(out) When non-@code{NULL} give the result of the
4786 operation, i.e., zero on success and non-zero on error. When @code{NULL} and
4787 an error occurs, then an error message is printed and the program is terminated.
4788 @item @var{dst_type} @tab intent(in) Give the type of the destination. When
4789 the destination is not an array, than the precise type, e.g. of a component in
4790 a derived type, is not known, but provided here.
4791 @end multitable
4792
4793 @item @emph{NOTES}
4794 It is permitted to have @var{image_index} equal the current image; the memory of
4795 the send-to and the send-from might (partially) overlap in that case. The
4796 implementation has to take care that it handles this case, e.g. using
4797 @code{memmove} which handles (partially) overlapping memory. If
4798 @var{may_require_tmp} is true, the library might additionally create a
4799 temporary variable, unless additional checks show that this is not required
4800 (e.g. because walking backward is possible or because both arrays are
4801 contiguous and @code{memmove} takes care of overlap issues).
4802
4803 Note that the assignment of a scalar to an array is permitted. In addition,
4804 the library has to handle numeric-type conversion and for strings, padding
4805 and different character kinds.
4806
4807 Because of the more complicated references possible some operations may be
4808 unsupported by certain libraries. The library is expected to issue a precise
4809 error message why the operation is not permitted.
4810 @end table
4811
4812
4813 @node _gfortran_caf_get_by_ref
4814 @subsection @code{_gfortran_caf_get_by_ref} --- Getting data from a remote image using enhanced references
4815 @cindex Coarray, _gfortran_caf_get_by_ref
4816
4817 @table @asis
4818 @item @emph{Description}:
4819 Called to get a scalar, an array section or a whole array from a remote image
4820 identified by the @var{image_index}.
4821
4822 @item @emph{Syntax}:
4823 @code{void _gfortran_caf_get_by_ref (caf_token_t token, int image_index,
4824 caf_reference_t *refs, gfc_descriptor_t *dst, int dst_kind, int src_kind,
4825 bool may_require_tmp, bool dst_reallocatable, int *stat, int src_type)}
4826
4827 @item @emph{Arguments}:
4828 @multitable @columnfractions .15 .70
4829 @item @var{token} @tab intent(in) An opaque pointer identifying the coarray.
4830 @item @var{image_index} @tab intent(in) The ID of the remote image; must be a
4831 positive number.
4832 @item @var{refs} @tab intent(in) The references to apply to the remote structure
4833 to get the data.
4834 @item @var{dst} @tab intent(in) Array descriptor of the local array to store
4835 the data transferred from the remote image. May be reallocated where needed
4836 and when @var{DST_REALLOCATABLE} allows it.
4837 @item @var{dst_kind} @tab intent(in) Kind of the destination argument
4838 @item @var{src_kind} @tab intent(in) Kind of the source argument
4839 @item @var{may_require_tmp} @tab intent(in) The variable is @code{false} when
4840 it is known at compile time that the @var{dest} and @var{src} either cannot
4841 overlap or overlap (fully or partially) such that walking @var{src} and
4842 @var{dest} in element wise element order (honoring the stride value) will not
4843 lead to wrong results. Otherwise, the value is @code{true}.
4844 @item @var{dst_reallocatable} @tab intent(in) Set when @var{DST} is of
4845 allocatable or pointer type and its refs allow reallocation, i.e., the full
4846 array or a component is referenced.
4847 @item @var{stat} @tab intent(out) When non-@code{NULL} give the result of the
4848 operation, i.e., zero on success and non-zero on error. When @code{NULL} and an
4849 error occurs, then an error message is printed and the program is terminated.
4850 @item @var{src_type} @tab intent(in) Give the type of the source. When the
4851 source is not an array, than the precise type, e.g. of a component in a
4852 derived type, is not known, but provided here.
4853 @end multitable
4854
4855 @item @emph{NOTES}
4856 It is permitted to have @code{image_index} equal the current image; the memory
4857 of the send-to and the send-from might (partially) overlap in that case. The
4858 implementation has to take care that it handles this case, e.g. using
4859 @code{memmove} which handles (partially) overlapping memory. If
4860 @var{may_require_tmp} is true, the library might additionally create a
4861 temporary variable, unless additional checks show that this is not required
4862 (e.g. because walking backward is possible or because both arrays are
4863 contiguous and @code{memmove} takes care of overlap issues).
4864
4865 Note that the library has to handle numeric-type conversion and for strings,
4866 padding and different character kinds.
4867
4868 Because of the more complicated references possible some operations may be
4869 unsupported by certain libraries. The library is expected to issue a precise
4870 error message why the operation is not permitted.
4871 @end table
4872
4873
4874 @node _gfortran_caf_sendget_by_ref
4875 @subsection @code{_gfortran_caf_sendget_by_ref} --- Sending data between remote images using enhanced references on both sides
4876 @cindex Coarray, _gfortran_caf_sendget_by_ref
4877
4878 @table @asis
4879 @item @emph{Description}:
4880 Called to send a scalar, an array section or a whole array from a remote image
4881 identified by the @var{src_image_index} to a remote image identified by the
4882 @var{dst_image_index}.
4883
4884 @item @emph{Syntax}:
4885 @code{void _gfortran_caf_sendget_by_ref (caf_token_t dst_token,
4886 int dst_image_index, caf_reference_t *dst_refs,
4887 caf_token_t src_token, int src_image_index, caf_reference_t *src_refs,
4888 int dst_kind, int src_kind, bool may_require_tmp, int *dst_stat,
4889 int *src_stat, int dst_type, int src_type)}
4890
4891 @item @emph{Arguments}:
4892 @multitable @columnfractions .15 .70
4893 @item @var{dst_token} @tab intent(in) An opaque pointer identifying the
4894 destination coarray.
4895 @item @var{dst_image_index} @tab intent(in) The ID of the destination remote
4896 image; must be a positive number.
4897 @item @var{dst_refs} @tab intent(in) The references on the remote array to store
4898 the data given by the source. Guaranteed to have at least one entry.
4899 @item @var{src_token} @tab intent(in) An opaque pointer identifying the source
4900 coarray.
4901 @item @var{src_image_index} @tab intent(in) The ID of the source remote image;
4902 must be a positive number.
4903 @item @var{src_refs} @tab intent(in) The references to apply to the remote
4904 structure to get the data.
4905 @item @var{dst_kind} @tab intent(in) Kind of the destination argument
4906 @item @var{src_kind} @tab intent(in) Kind of the source argument
4907 @item @var{may_require_tmp} @tab intent(in) The variable is @code{false} when
4908 it is known at compile time that the @var{dest} and @var{src} either cannot
4909 overlap or overlap (fully or partially) such that walking @var{src} and
4910 @var{dest} in element wise element order (honoring the stride value) will not
4911 lead to wrong results. Otherwise, the value is @code{true}.
4912 @item @var{dst_stat} @tab intent(out) when non-@code{NULL} give the result of
4913 the send-operation, i.e., zero on success and non-zero on error. When
4914 @code{NULL} and an error occurs, then an error message is printed and the
4915 program is terminated.
4916 @item @var{src_stat} @tab intent(out) When non-@code{NULL} give the result of
4917 the get-operation, i.e., zero on success and non-zero on error. When
4918 @code{NULL} and an error occurs, then an error message is printed and the
4919 program is terminated.
4920 @item @var{dst_type} @tab intent(in) Give the type of the destination. When
4921 the destination is not an array, than the precise type, e.g. of a component in
4922 a derived type, is not known, but provided here.
4923 @item @var{src_type} @tab intent(in) Give the type of the source. When the
4924 source is not an array, than the precise type, e.g. of a component in a
4925 derived type, is not known, but provided here.
4926 @end multitable
4927
4928 @item @emph{NOTES}
4929 It is permitted to have the same image index for both @var{src_image_index} and
4930 @var{dst_image_index}; the memory of the send-to and the send-from might
4931 (partially) overlap in that case. The implementation has to take care that it
4932 handles this case, e.g. using @code{memmove} which handles (partially)
4933 overlapping memory. If @var{may_require_tmp} is true, the library
4934 might additionally create a temporary variable, unless additional checks show
4935 that this is not required (e.g. because walking backward is possible or because
4936 both arrays are contiguous and @code{memmove} takes care of overlap issues).
4937
4938 Note that the assignment of a scalar to an array is permitted. In addition,
4939 the library has to handle numeric-type conversion and for strings, padding and
4940 different character kinds.
4941
4942 Because of the more complicated references possible some operations may be
4943 unsupported by certain libraries. The library is expected to issue a precise
4944 error message why the operation is not permitted.
4945 @end table
4946
4947
4948 @node _gfortran_caf_lock
4949 @subsection @code{_gfortran_caf_lock} --- Locking a lock variable
4950 @cindex Coarray, _gfortran_caf_lock
4951
4952 @table @asis
4953 @item @emph{Description}:
4954 Acquire a lock on the given image on a scalar locking variable or for the
4955 given array element for an array-valued variable. If the @var{aquired_lock}
4956 is @code{NULL}, the function returns after having obtained the lock. If it is
4957 non-@code{NULL}, then @var{acquired_lock} is assigned the value true (one) when
4958 the lock could be obtained and false (zero) otherwise. Locking a lock variable
4959 which has already been locked by the same image is an error.
4960
4961 @item @emph{Syntax}:
4962 @code{void _gfortran_caf_lock (caf_token_t token, size_t index, int image_index,
4963 int *aquired_lock, int *stat, char *errmsg, size_t errmsg_len)}
4964
4965 @item @emph{Arguments}:
4966 @multitable @columnfractions .15 .70
4967 @item @var{token} @tab intent(in) An opaque pointer identifying the coarray.
4968 @item @var{index} @tab intent(in) Array index; first array index is 0. For
4969 scalars, it is always 0.
4970 @item @var{image_index} @tab intent(in) The ID of the remote image; must be a
4971 positive number.
4972 @item @var{aquired_lock} @tab intent(out) If not NULL, it returns whether lock
4973 could be obtained.
4974 @item @var{stat} @tab intent(out) Stores the STAT=; may be NULL.
4975 @item @var{errmsg} @tab intent(out) When an error occurs, this will be set to
4976 an error message; may be NULL.
4977 @item @var{errmsg_len} @tab intent(in) the buffer size of errmsg
4978 @end multitable
4979
4980 @item @emph{NOTES}
4981 This function is also called for critical blocks; for those, the array index
4982 is always zero and the image index is one. Libraries are permitted to use other
4983 images for critical-block locking variables.
4984 @end table
4985
4986 @node _gfortran_caf_unlock
4987 @subsection @code{_gfortran_caf_lock} --- Unlocking a lock variable
4988 @cindex Coarray, _gfortran_caf_unlock
4989
4990 @table @asis
4991 @item @emph{Description}:
4992 Release a lock on the given image on a scalar locking variable or for the
4993 given array element for an array-valued variable. Unlocking a lock variable
4994 which is unlocked or has been locked by a different image is an error.
4995
4996 @item @emph{Syntax}:
4997 @code{void _gfortran_caf_unlock (caf_token_t token, size_t index, int image_index,
4998 int *stat, char *errmsg, size_t errmsg_len)}
4999
5000 @item @emph{Arguments}:
5001 @multitable @columnfractions .15 .70
5002 @item @var{token} @tab intent(in) An opaque pointer identifying the coarray.
5003 @item @var{index} @tab intent(in) Array index; first array index is 0. For
5004 scalars, it is always 0.
5005 @item @var{image_index} @tab intent(in) The ID of the remote image; must be a
5006 positive number.
5007 @item @var{stat} @tab intent(out) For allocatable coarrays, stores the STAT=;
5008 may be NULL.
5009 @item @var{errmsg} @tab intent(out) When an error occurs, this will be set to
5010 an error message; may be NULL.
5011 @item @var{errmsg_len} @tab intent(in) the buffer size of errmsg
5012 @end multitable
5013
5014 @item @emph{NOTES}
5015 This function is also called for critical block; for those, the array index
5016 is always zero and the image index is one. Libraries are permitted to use other
5017 images for critical-block locking variables.
5018 @end table
5019
5020 @node _gfortran_caf_event_post
5021 @subsection @code{_gfortran_caf_event_post} --- Post an event
5022 @cindex Coarray, _gfortran_caf_event_post
5023
5024 @table @asis
5025 @item @emph{Description}:
5026 Increment the event count of the specified event variable.
5027
5028 @item @emph{Syntax}:
5029 @code{void _gfortran_caf_event_post (caf_token_t token, size_t index,
5030 int image_index, int *stat, char *errmsg, size_t errmsg_len)}
5031
5032 @item @emph{Arguments}:
5033 @multitable @columnfractions .15 .70
5034 @item @var{token} @tab intent(in) An opaque pointer identifying the coarray.
5035 @item @var{index} @tab intent(in) Array index; first array index is 0. For
5036 scalars, it is always 0.
5037 @item @var{image_index} @tab intent(in) The ID of the remote image; must be a
5038 positive number; zero indicates the current image, when accessed noncoindexed.
5039 @item @var{stat} @tab intent(out) Stores the STAT=; may be NULL.
5040 @item @var{errmsg} @tab intent(out) When an error occurs, this will be set to
5041 an error message; may be NULL.
5042 @item @var{errmsg_len} @tab intent(in) the buffer size of errmsg
5043 @end multitable
5044
5045 @item @emph{NOTES}
5046 This acts like an atomic add of one to the remote image's event variable.
5047 The statement is an image-control statement but does not imply sync memory.
5048 Still, all preceeding push communications of this image to the specified
5049 remote image have to be completed before @code{event_wait} on the remote
5050 image returns.
5051 @end table
5052
5053
5054
5055 @node _gfortran_caf_event_wait
5056 @subsection @code{_gfortran_caf_event_wait} --- Wait that an event occurred
5057 @cindex Coarray, _gfortran_caf_event_wait
5058
5059 @table @asis
5060 @item @emph{Description}:
5061 Wait until the event count has reached at least the specified
5062 @var{until_count}; if so, atomically decrement the event variable by this
5063 amount and return.
5064
5065 @item @emph{Syntax}:
5066 @code{void _gfortran_caf_event_wait (caf_token_t token, size_t index,
5067 int until_count, int *stat, char *errmsg, size_t errmsg_len)}
5068
5069 @item @emph{Arguments}:
5070 @multitable @columnfractions .15 .70
5071 @item @var{token} @tab intent(in) An opaque pointer identifying the coarray.
5072 @item @var{index} @tab intent(in) Array index; first array index is 0. For
5073 scalars, it is always 0.
5074 @item @var{until_count} @tab intent(in) The number of events which have to be
5075 available before the function returns.
5076 @item @var{stat} @tab intent(out) Stores the STAT=; may be NULL.
5077 @item @var{errmsg} @tab intent(out) When an error occurs, this will be set to
5078 an error message; may be NULL.
5079 @item @var{errmsg_len} @tab intent(in) the buffer size of errmsg
5080 @end multitable
5081
5082 @item @emph{NOTES}
5083 This function only operates on a local coarray. It acts like a loop checking
5084 atomically the value of the event variable, breaking if the value is greater
5085 or equal the requested number of counts. Before the function returns, the
5086 event variable has to be decremented by the requested @var{until_count} value.
5087 A possible implementation would be a busy loop for a certain number of spins
5088 (possibly depending on the number of threads relative to the number of available
5089 cores) followed by another waiting strategy such as a sleeping wait (possibly
5090 with an increasing number of sleep time) or, if possible, a futex wait.
5091
5092 The statement is an image-control statement but does not imply sync memory.
5093 Still, all preceeding push communications of this image to the specified
5094 remote image have to be completed before @code{event_wait} on the remote
5095 image returns.
5096 @end table
5097
5098
5099
5100 @node _gfortran_caf_event_query
5101 @subsection @code{_gfortran_caf_event_query} --- Query event count
5102 @cindex Coarray, _gfortran_caf_event_query
5103
5104 @table @asis
5105 @item @emph{Description}:
5106 Return the event count of the specified event variable.
5107
5108 @item @emph{Syntax}:
5109 @code{void _gfortran_caf_event_query (caf_token_t token, size_t index,
5110 int image_index, int *count, int *stat)}
5111
5112 @item @emph{Arguments}:
5113 @multitable @columnfractions .15 .70
5114 @item @var{token} @tab intent(in) An opaque pointer identifying the coarray.
5115 @item @var{index} @tab intent(in) Array index; first array index is 0. For
5116 scalars, it is always 0.
5117 @item @var{image_index} @tab intent(in) The ID of the remote image; must be a
5118 positive number; zero indicates the current image when accessed noncoindexed.
5119 @item @var{count} @tab intent(out) The number of events currently posted to
5120 the event variable.
5121 @item @var{stat} @tab intent(out) Stores the STAT=; may be NULL.
5122 @end multitable
5123
5124 @item @emph{NOTES}
5125 The typical use is to check the local event variable to only call
5126 @code{event_wait} when the data is available. However, a coindexed variable
5127 is permitted; there is no ordering or synchronization implied. It acts like
5128 an atomic fetch of the value of the event variable.
5129 @end table
5130
5131
5132
5133 @node _gfortran_caf_sync_all
5134 @subsection @code{_gfortran_caf_sync_all} --- All-image barrier
5135 @cindex Coarray, _gfortran_caf_sync_all
5136
5137 @table @asis
5138 @item @emph{Description}:
5139 Synchronization of all images in the current team; the program only continues
5140 on a given image after this function has been called on all images of the
5141 current team. Additionally, it ensures that all pending data transfers of
5142 previous segment have completed.
5143
5144 @item @emph{Syntax}:
5145 @code{void _gfortran_caf_sync_all (int *stat, char *errmsg, size_t errmsg_len)}
5146
5147 @item @emph{Arguments}:
5148 @multitable @columnfractions .15 .70
5149 @item @var{stat} @tab intent(out) Stores the status STAT= and may be NULL.
5150 @item @var{errmsg} @tab intent(out) When an error occurs, this will be set to
5151 an error message; may be NULL.
5152 @item @var{errmsg_len} @tab intent(in) the buffer size of errmsg
5153 @end multitable
5154 @end table
5155
5156
5157
5158 @node _gfortran_caf_sync_images
5159 @subsection @code{_gfortran_caf_sync_images} --- Barrier for selected images
5160 @cindex Coarray, _gfortran_caf_sync_images
5161
5162 @table @asis
5163 @item @emph{Description}:
5164 Synchronization between the specified images; the program only continues on a
5165 given image after this function has been called on all images specified for
5166 that image. Note that one image can wait for all other images in the current
5167 team (e.g. via @code{sync images(*)}) while those only wait for that specific
5168 image. Additionally, @code{sync images} ensures that all pending data
5169 transfers of previous segments have completed.
5170
5171 @item @emph{Syntax}:
5172 @code{void _gfortran_caf_sync_images (int count, int images[], int *stat,
5173 char *errmsg, size_t errmsg_len)}
5174
5175 @item @emph{Arguments}:
5176 @multitable @columnfractions .15 .70
5177 @item @var{count} @tab intent(in) The number of images which are provided in
5178 the next argument. For a zero-sized array, the value is zero. For
5179 @code{sync images (*)}, the value is @math{-1}.
5180 @item @var{images} @tab intent(in) An array with the images provided by the
5181 user. If @var{count} is zero, a NULL pointer is passed.
5182 @item @var{stat} @tab intent(out) Stores the status STAT= and may be NULL.
5183 @item @var{errmsg} @tab intent(out) When an error occurs, this will be set to
5184 an error message; may be NULL.
5185 @item @var{errmsg_len} @tab intent(in) the buffer size of errmsg
5186 @end multitable
5187 @end table
5188
5189
5190
5191 @node _gfortran_caf_sync_memory
5192 @subsection @code{_gfortran_caf_sync_memory} --- Wait for completion of segment-memory operations
5193 @cindex Coarray, _gfortran_caf_sync_memory
5194
5195 @table @asis
5196 @item @emph{Description}:
5197 Acts as optimization barrier between different segments. It also ensures that
5198 all pending memory operations of this image have been completed.
5199
5200 @item @emph{Syntax}:
5201 @code{void _gfortran_caf_sync_memory (int *stat, char *errmsg, size_t errmsg_len)}
5202
5203 @item @emph{Arguments}:
5204 @multitable @columnfractions .15 .70
5205 @item @var{stat} @tab intent(out) Stores the status STAT= and may be NULL.
5206 @item @var{errmsg} @tab intent(out) When an error occurs, this will be set to
5207 an error message; may be NULL.
5208 @item @var{errmsg_len} @tab intent(in) the buffer size of errmsg
5209 @end multitable
5210
5211 @item @emph{NOTE} A simple implementation could be
5212 @code{__asm__ __volatile__ ("":::"memory")} to prevent code movements.
5213 @end table
5214
5215
5216
5217 @node _gfortran_caf_error_stop
5218 @subsection @code{_gfortran_caf_error_stop} --- Error termination with exit code
5219 @cindex Coarray, _gfortran_caf_error_stop
5220
5221 @table @asis
5222 @item @emph{Description}:
5223 Invoked for an @code{ERROR STOP} statement which has an integer argument. The
5224 function should terminate the program with the specified exit code.
5225
5226
5227 @item @emph{Syntax}:
5228 @code{void _gfortran_caf_error_stop (int error)}
5229
5230 @item @emph{Arguments}:
5231 @multitable @columnfractions .15 .70
5232 @item @var{error} @tab intent(in) The exit status to be used.
5233 @end multitable
5234 @end table
5235
5236
5237
5238 @node _gfortran_caf_error_stop_str
5239 @subsection @code{_gfortran_caf_error_stop_str} --- Error termination with string
5240 @cindex Coarray, _gfortran_caf_error_stop_str
5241
5242 @table @asis
5243 @item @emph{Description}:
5244 Invoked for an @code{ERROR STOP} statement which has a string as argument. The
5245 function should terminate the program with a nonzero-exit code.
5246
5247 @item @emph{Syntax}:
5248 @code{void _gfortran_caf_error_stop (const char *string, size_t len)}
5249
5250 @item @emph{Arguments}:
5251 @multitable @columnfractions .15 .70
5252 @item @var{string} @tab intent(in) the error message (not zero terminated)
5253 @item @var{len} @tab intent(in) the length of the string
5254 @end multitable
5255 @end table
5256
5257
5258
5259 @node _gfortran_caf_fail_image
5260 @subsection @code{_gfortran_caf_fail_image} --- Mark the image failed and end its execution
5261 @cindex Coarray, _gfortran_caf_fail_image
5262
5263 @table @asis
5264 @item @emph{Description}:
5265 Invoked for an @code{FAIL IMAGE} statement. The function should terminate the
5266 current image.
5267
5268 @item @emph{Syntax}:
5269 @code{void _gfortran_caf_fail_image ()}
5270
5271 @item @emph{NOTES}
5272 This function follows TS18508.
5273 @end table
5274
5275
5276
5277 @node _gfortran_caf_atomic_define
5278 @subsection @code{_gfortran_caf_atomic_define} --- Atomic variable assignment
5279 @cindex Coarray, _gfortran_caf_atomic_define
5280
5281 @table @asis
5282 @item @emph{Description}:
5283 Assign atomically a value to an integer or logical variable.
5284
5285 @item @emph{Syntax}:
5286 @code{void _gfortran_caf_atomic_define (caf_token_t token, size_t offset,
5287 int image_index, void *value, int *stat, int type, int kind)}
5288
5289 @item @emph{Arguments}:
5290 @multitable @columnfractions .15 .70
5291 @item @var{token} @tab intent(in) An opaque pointer identifying the coarray.
5292 @item @var{offset} @tab intent(in) By which amount of bytes the actual data is
5293 shifted compared to the base address of the coarray.
5294 @item @var{image_index} @tab intent(in) The ID of the remote image; must be a
5295 positive number; zero indicates the current image when used noncoindexed.
5296 @item @var{value} @tab intent(in) the value to be assigned, passed by reference
5297 @item @var{stat} @tab intent(out) Stores the status STAT= and may be NULL.
5298 @item @var{type} @tab intent(in) The data type, i.e. @code{BT_INTEGER} (1) or
5299 @code{BT_LOGICAL} (2).
5300 @item @var{kind} @tab intent(in) The kind value (only 4; always @code{int})
5301 @end multitable
5302 @end table
5303
5304
5305
5306 @node _gfortran_caf_atomic_ref
5307 @subsection @code{_gfortran_caf_atomic_ref} --- Atomic variable reference
5308 @cindex Coarray, _gfortran_caf_atomic_ref
5309
5310 @table @asis
5311 @item @emph{Description}:
5312 Reference atomically a value of a kind-4 integer or logical variable.
5313
5314 @item @emph{Syntax}:
5315 @code{void _gfortran_caf_atomic_ref (caf_token_t token, size_t offset,
5316 int image_index, void *value, int *stat, int type, int kind)}
5317
5318 @item @emph{Arguments}:
5319 @multitable @columnfractions .15 .70
5320 @item @var{token} @tab intent(in) An opaque pointer identifying the coarray.
5321 @item @var{offset} @tab intent(in) By which amount of bytes the actual data is
5322 shifted compared to the base address of the coarray.
5323 @item @var{image_index} @tab intent(in) The ID of the remote image; must be a
5324 positive number; zero indicates the current image when used noncoindexed.
5325 @item @var{value} @tab intent(out) The variable assigned the atomically
5326 referenced variable.
5327 @item @var{stat} @tab intent(out) Stores the status STAT= and may be NULL.
5328 @item @var{type} @tab the data type, i.e. @code{BT_INTEGER} (1) or
5329 @code{BT_LOGICAL} (2).
5330 @item @var{kind} @tab The kind value (only 4; always @code{int})
5331 @end multitable
5332 @end table
5333
5334
5335
5336 @node _gfortran_caf_atomic_cas
5337 @subsection @code{_gfortran_caf_atomic_cas} --- Atomic compare and swap
5338 @cindex Coarray, _gfortran_caf_atomic_cas
5339
5340 @table @asis
5341 @item @emph{Description}:
5342 Atomic compare and swap of a kind-4 integer or logical variable. Assigns
5343 atomically the specified value to the atomic variable, if the latter has
5344 the value specified by the passed condition value.
5345
5346 @item @emph{Syntax}:
5347 @code{void _gfortran_caf_atomic_cas (caf_token_t token, size_t offset,
5348 int image_index, void *old, void *compare, void *new_val, int *stat,
5349 int type, int kind)}
5350
5351 @item @emph{Arguments}:
5352 @multitable @columnfractions .15 .70
5353 @item @var{token} @tab intent(in) An opaque pointer identifying the coarray.
5354 @item @var{offset} @tab intent(in) By which amount of bytes the actual data is
5355 shifted compared to the base address of the coarray.
5356 @item @var{image_index} @tab intent(in) The ID of the remote image; must be a
5357 positive number; zero indicates the current image when used noncoindexed.
5358 @item @var{old} @tab intent(out) The value which the atomic variable had
5359 just before the cas operation.
5360 @item @var{compare} @tab intent(in) The value used for comparision.
5361 @item @var{new_val} @tab intent(in) The new value for the atomic variable,
5362 assigned to the atomic variable, if @code{compare} equals the value of the
5363 atomic variable.
5364 @item @var{stat} @tab intent(out) Stores the status STAT= and may be NULL.
5365 @item @var{type} @tab intent(in) the data type, i.e. @code{BT_INTEGER} (1) or
5366 @code{BT_LOGICAL} (2).
5367 @item @var{kind} @tab intent(in) The kind value (only 4; always @code{int})
5368 @end multitable
5369 @end table
5370
5371
5372
5373 @node _gfortran_caf_atomic_op
5374 @subsection @code{_gfortran_caf_atomic_op} --- Atomic operation
5375 @cindex Coarray, _gfortran_caf_atomic_op
5376
5377 @table @asis
5378 @item @emph{Description}:
5379 Apply an operation atomically to an atomic integer or logical variable.
5380 After the operation, @var{old} contains the value just before the operation,
5381 which, respectively, adds (GFC_CAF_ATOMIC_ADD) atomically the @code{value} to
5382 the atomic integer variable or does a bitwise AND, OR or exclusive OR
5383 between the atomic variable and @var{value}; the result is then stored in the
5384 atomic variable.
5385
5386 @item @emph{Syntax}:
5387 @code{void _gfortran_caf_atomic_op (int op, caf_token_t token, size_t offset,
5388 int image_index, void *value, void *old, int *stat, int type, int kind)}
5389
5390 @item @emph{Arguments}:
5391 @multitable @columnfractions .15 .70
5392 @item @var{op} @tab intent(in) the operation to be performed; possible values
5393 @code{GFC_CAF_ATOMIC_ADD} (1), @code{GFC_CAF_ATOMIC_AND} (2),
5394 @code{GFC_CAF_ATOMIC_OR} (3), @code{GFC_CAF_ATOMIC_XOR} (4).
5395 @item @var{token} @tab intent(in) An opaque pointer identifying the coarray.
5396 @item @var{offset} @tab intent(in) By which amount of bytes the actual data is
5397 shifted compared to the base address of the coarray.
5398 @item @var{image_index} @tab intent(in) The ID of the remote image; must be a
5399 positive number; zero indicates the current image when used noncoindexed.
5400 @item @var{old} @tab intent(out) The value which the atomic variable had
5401 just before the atomic operation.
5402 @item @var{val} @tab intent(in) The new value for the atomic variable,
5403 assigned to the atomic variable, if @code{compare} equals the value of the
5404 atomic variable.
5405 @item @var{stat} @tab intent(out) Stores the status STAT= and may be NULL.
5406 @item @var{type} @tab intent(in) the data type, i.e. @code{BT_INTEGER} (1) or
5407 @code{BT_LOGICAL} (2)
5408 @item @var{kind} @tab intent(in) the kind value (only 4; always @code{int})
5409 @end multitable
5410 @end table
5411
5412
5413
5414
5415 @node _gfortran_caf_co_broadcast
5416 @subsection @code{_gfortran_caf_co_broadcast} --- Sending data to all images
5417 @cindex Coarray, _gfortran_caf_co_broadcast
5418
5419 @table @asis
5420 @item @emph{Description}:
5421 Distribute a value from a given image to all other images in the team. Has to
5422 be called collectively.
5423
5424 @item @emph{Syntax}:
5425 @code{void _gfortran_caf_co_broadcast (gfc_descriptor_t *a,
5426 int source_image, int *stat, char *errmsg, size_t errmsg_len)}
5427
5428 @item @emph{Arguments}:
5429 @multitable @columnfractions .15 .70
5430 @item @var{a} @tab intent(inout) An array descriptor with the data to be
5431 broadcasted (on @var{source_image}) or to be received (other images).
5432 @item @var{source_image} @tab intent(in) The ID of the image from which the
5433 data should be broadcasted.
5434 @item @var{stat} @tab intent(out) Stores the status STAT= and may be NULL.
5435 @item @var{errmsg} @tab intent(out) When an error occurs, this will be set to
5436 an error message; may be NULL.
5437 @item @var{errmsg_len} @tab intent(in) the buffer size of errmsg.
5438 @end multitable
5439 @end table
5440
5441
5442
5443 @node _gfortran_caf_co_max
5444 @subsection @code{_gfortran_caf_co_max} --- Collective maximum reduction
5445 @cindex Coarray, _gfortran_caf_co_max
5446
5447 @table @asis
5448 @item @emph{Description}:
5449 Calculates for each array element of the variable @var{a} the maximum
5450 value for that element in the current team; if @var{result_image} has the
5451 value 0, the result shall be stored on all images, otherwise, only on the
5452 specified image. This function operates on numeric values and character
5453 strings.
5454
5455 @item @emph{Syntax}:
5456 @code{void _gfortran_caf_co_max (gfc_descriptor_t *a, int result_image,
5457 int *stat, char *errmsg, int a_len, size_t errmsg_len)}
5458
5459 @item @emph{Arguments}:
5460 @multitable @columnfractions .15 .70
5461 @item @var{a} @tab intent(inout) An array descriptor for the data to be
5462 processed. On the destination image(s) the result overwrites the old content.
5463 @item @var{result_image} @tab intent(in) The ID of the image to which the
5464 reduced value should be copied to; if zero, it has to be copied to all images.
5465 @item @var{stat} @tab intent(out) Stores the status STAT= and may be NULL.
5466 @item @var{errmsg} @tab intent(out) When an error occurs, this will be set to
5467 an error message; may be NULL.
5468 @item @var{a_len} @tab intent(in) the string length of argument @var{a}
5469 @item @var{errmsg_len} @tab intent(in) the buffer size of errmsg
5470 @end multitable
5471
5472 @item @emph{NOTES}
5473 If @var{result_image} is nonzero, the data in the array descriptor @var{a} on
5474 all images except of the specified one become undefined; hence, the library may
5475 make use of this.
5476 @end table
5477
5478
5479
5480 @node _gfortran_caf_co_min
5481 @subsection @code{_gfortran_caf_co_min} --- Collective minimum reduction
5482 @cindex Coarray, _gfortran_caf_co_min
5483
5484 @table @asis
5485 @item @emph{Description}:
5486 Calculates for each array element of the variable @var{a} the minimum
5487 value for that element in the current team; if @var{result_image} has the
5488 value 0, the result shall be stored on all images, otherwise, only on the
5489 specified image. This function operates on numeric values and character
5490 strings.
5491
5492 @item @emph{Syntax}:
5493 @code{void _gfortran_caf_co_min (gfc_descriptor_t *a, int result_image,
5494 int *stat, char *errmsg, int a_len, size_t errmsg_len)}
5495
5496 @item @emph{Arguments}:
5497 @multitable @columnfractions .15 .70
5498 @item @var{a} @tab intent(inout) An array descriptor for the data to be
5499 processed. On the destination image(s) the result overwrites the old content.
5500 @item @var{result_image} @tab intent(in) The ID of the image to which the
5501 reduced value should be copied to; if zero, it has to be copied to all images.
5502 @item @var{stat} @tab intent(out) Stores the status STAT= and may be NULL.
5503 @item @var{errmsg} @tab intent(out) When an error occurs, this will be set to
5504 an error message; may be NULL.
5505 @item @var{a_len} @tab intent(in) the string length of argument @var{a}
5506 @item @var{errmsg_len} @tab intent(in) the buffer size of errmsg
5507 @end multitable
5508
5509 @item @emph{NOTES}
5510 If @var{result_image} is nonzero, the data in the array descriptor @var{a} on
5511 all images except of the specified one become undefined; hence, the library may
5512 make use of this.
5513 @end table
5514
5515
5516
5517 @node _gfortran_caf_co_sum
5518 @subsection @code{_gfortran_caf_co_sum} --- Collective summing reduction
5519 @cindex Coarray, _gfortran_caf_co_sum
5520
5521 @table @asis
5522 @item @emph{Description}:
5523 Calculates for each array element of the variable @var{a} the sum of all
5524 values for that element in the current team; if @var{result_image} has the
5525 value 0, the result shall be stored on all images, otherwise, only on the
5526 specified image. This function operates on numeric values only.
5527
5528 @item @emph{Syntax}:
5529 @code{void _gfortran_caf_co_sum (gfc_descriptor_t *a, int result_image,
5530 int *stat, char *errmsg, size_t errmsg_len)}
5531
5532 @item @emph{Arguments}:
5533 @multitable @columnfractions .15 .70
5534 @item @var{a} @tab intent(inout) An array descriptor with the data to be
5535 processed. On the destination image(s) the result overwrites the old content.
5536 @item @var{result_image} @tab intent(in) The ID of the image to which the
5537 reduced value should be copied to; if zero, it has to be copied to all images.
5538 @item @var{stat} @tab intent(out) Stores the status STAT= and may be NULL.
5539 @item @var{errmsg} @tab intent(out) When an error occurs, this will be set to
5540 an error message; may be NULL.
5541 @item @var{errmsg_len} @tab intent(in) the buffer size of errmsg
5542 @end multitable
5543
5544 @item @emph{NOTES}
5545 If @var{result_image} is nonzero, the data in the array descriptor @var{a} on
5546 all images except of the specified one become undefined; hence, the library may
5547 make use of this.
5548 @end table
5549
5550
5551
5552 @node _gfortran_caf_co_reduce
5553 @subsection @code{_gfortran_caf_co_reduce} --- Generic collective reduction
5554 @cindex Coarray, _gfortran_caf_co_reduce
5555
5556 @table @asis
5557 @item @emph{Description}:
5558 Calculates for each array element of the variable @var{a} the reduction
5559 value for that element in the current team; if @var{result_image} has the
5560 value 0, the result shall be stored on all images, otherwise, only on the
5561 specified image. The @var{opr} is a pure function doing a mathematically
5562 commutative and associative operation.
5563
5564 The @var{opr_flags} denote the following; the values are bitwise ored.
5565 @code{GFC_CAF_BYREF} (1) if the result should be returned
5566 by reference; @code{GFC_CAF_HIDDENLEN} (2) whether the result and argument
5567 string lengths shall be specified as hidden arguments;
5568 @code{GFC_CAF_ARG_VALUE} (4) whether the arguments shall be passed by value,
5569 @code{GFC_CAF_ARG_DESC} (8) whether the arguments shall be passed by descriptor.
5570
5571
5572 @item @emph{Syntax}:
5573 @code{void _gfortran_caf_co_reduce (gfc_descriptor_t *a,
5574 void * (*opr) (void *, void *), int opr_flags, int result_image,
5575 int *stat, char *errmsg, int a_len, size_t errmsg_len)}
5576
5577 @item @emph{Arguments}:
5578 @multitable @columnfractions .15 .70
5579 @item @var{a} @tab intent(inout) An array descriptor with the data to be
5580 processed. On the destination image(s) the result overwrites the old content.
5581 @item @var{opr} @tab intent(in) Function pointer to the reduction function
5582 @item @var{opr_flags} @tab intent(in) Flags regarding the reduction function
5583 @item @var{result_image} @tab intent(in) The ID of the image to which the
5584 reduced value should be copied to; if zero, it has to be copied to all images.
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{a_len} @tab intent(in) the string length of argument @var{a}
5589 @item @var{errmsg_len} @tab intent(in) the buffer size of errmsg
5590 @end multitable
5591
5592 @item @emph{NOTES}
5593 If @var{result_image} is nonzero, the data in the array descriptor @var{a} on
5594 all images except of the specified one become undefined; hence, the library may
5595 make use of this.
5596
5597 For character arguments, the result is passed as first argument, followed
5598 by the result string length, next come the two string arguments, followed
5599 by the two hidden string length arguments. With C binding, there are no hidden
5600 arguments and by-reference passing and either only a single character is passed
5601 or an array descriptor.
5602 @end table
5603
5604
5605 @c Intrinsic Procedures
5606 @c ---------------------------------------------------------------------
5607
5608 @include intrinsic.texi
5609
5610
5611 @tex
5612 \blankpart
5613 @end tex
5614
5615 @c ---------------------------------------------------------------------
5616 @c Contributing
5617 @c ---------------------------------------------------------------------
5618
5619 @node Contributing
5620 @unnumbered Contributing
5621 @cindex Contributing
5622
5623 Free software is only possible if people contribute to efforts
5624 to create it.
5625 We're always in need of more people helping out with ideas
5626 and comments, writing documentation and contributing code.
5627
5628 If you want to contribute to GNU Fortran,
5629 have a look at the long lists of projects you can take on.
5630 Some of these projects are small,
5631 some of them are large;
5632 some are completely orthogonal to the rest of what is
5633 happening on GNU Fortran,
5634 but others are ``mainstream'' projects in need of enthusiastic hackers.
5635 All of these projects are important!
5636 We will eventually get around to the things here,
5637 but they are also things doable by someone who is willing and able.
5638
5639 @menu
5640 * Contributors::
5641 * Projects::
5642 * Proposed Extensions::
5643 @end menu
5644
5645
5646 @node Contributors
5647 @section Contributors to GNU Fortran
5648 @cindex Contributors
5649 @cindex Credits
5650 @cindex Authors
5651
5652 Most of the parser was hand-crafted by @emph{Andy Vaught}, who is
5653 also the initiator of the whole project. Thanks Andy!
5654 Most of the interface with GCC was written by @emph{Paul Brook}.
5655
5656 The following individuals have contributed code and/or
5657 ideas and significant help to the GNU Fortran project
5658 (in alphabetical order):
5659
5660 @itemize @minus
5661 @item Janne Blomqvist
5662 @item Steven Bosscher
5663 @item Paul Brook
5664 @item Tobias Burnus
5665 @item Fran@,{c}ois-Xavier Coudert
5666 @item Bud Davis
5667 @item Jerry DeLisle
5668 @item Erik Edelmann
5669 @item Bernhard Fischer
5670 @item Daniel Franke
5671 @item Richard Guenther
5672 @item Richard Henderson
5673 @item Katherine Holcomb
5674 @item Jakub Jelinek
5675 @item Niels Kristian Bech Jensen
5676 @item Steven Johnson
5677 @item Steven G. Kargl
5678 @item Thomas Koenig
5679 @item Asher Langton
5680 @item H. J. Lu
5681 @item Toon Moene
5682 @item Brooks Moses
5683 @item Andrew Pinski
5684 @item Tim Prince
5685 @item Christopher D. Rickett
5686 @item Richard Sandiford
5687 @item Tobias Schl@"uter
5688 @item Roger Sayle
5689 @item Paul Thomas
5690 @item Andy Vaught
5691 @item Feng Wang
5692 @item Janus Weil
5693 @item Daniel Kraft
5694 @end itemize
5695
5696 The following people have contributed bug reports,
5697 smaller or larger patches,
5698 and much needed feedback and encouragement for the
5699 GNU Fortran project:
5700
5701 @itemize @minus
5702 @item Bill Clodius
5703 @item Dominique d'Humi@`eres
5704 @item Kate Hedstrom
5705 @item Erik Schnetter
5706 @item Joost VandeVondele
5707 @end itemize
5708
5709 Many other individuals have helped debug,
5710 test and improve the GNU Fortran compiler over the past few years,
5711 and we welcome you to do the same!
5712 If you already have done so,
5713 and you would like to see your name listed in the
5714 list above, please contact us.
5715
5716
5717 @node Projects
5718 @section Projects
5719
5720 @table @emph
5721
5722 @item Help build the test suite
5723 Solicit more code for donation to the test suite: the more extensive the
5724 testsuite, the smaller the risk of breaking things in the future! We can
5725 keep code private on request.
5726
5727 @item Bug hunting/squishing
5728 Find bugs and write more test cases! Test cases are especially very
5729 welcome, because it allows us to concentrate on fixing bugs instead of
5730 isolating them. Going through the bugzilla database at
5731 @url{https://gcc.gnu.org/@/bugzilla/} to reduce testcases posted there and
5732 add more information (for example, for which version does the testcase
5733 work, for which versions does it fail?) is also very helpful.
5734
5735 @end table
5736
5737
5738 @node Proposed Extensions
5739 @section Proposed Extensions
5740
5741 Here's a list of proposed extensions for the GNU Fortran compiler, in no particular
5742 order. Most of these are necessary to be fully compatible with
5743 existing Fortran compilers, but they are not part of the official
5744 J3 Fortran 95 standard.
5745
5746 @subsection Compiler extensions:
5747 @itemize @bullet
5748 @item
5749 User-specified alignment rules for structures.
5750
5751 @item
5752 Automatically extend single precision constants to double.
5753
5754 @item
5755 Compile code that conserves memory by dynamically allocating common and
5756 module storage either on stack or heap.
5757
5758 @item
5759 Compile flag to generate code for array conformance checking (suggest -CC).
5760
5761 @item
5762 User control of symbol names (underscores, etc).
5763
5764 @item
5765 Compile setting for maximum size of stack frame size before spilling
5766 parts to static or heap.
5767
5768 @item
5769 Flag to force local variables into static space.
5770
5771 @item
5772 Flag to force local variables onto stack.
5773 @end itemize
5774
5775
5776 @subsection Environment Options
5777 @itemize @bullet
5778 @item
5779 Pluggable library modules for random numbers, linear algebra.
5780 LA should use BLAS calling conventions.
5781
5782 @item
5783 Environment variables controlling actions on arithmetic exceptions like
5784 overflow, underflow, precision loss---Generate NaN, abort, default.
5785 action.
5786
5787 @item
5788 Set precision for fp units that support it (i387).
5789
5790 @item
5791 Variable for setting fp rounding mode.
5792
5793 @item
5794 Variable to fill uninitialized variables with a user-defined bit
5795 pattern.
5796
5797 @item
5798 Environment variable controlling filename that is opened for that unit
5799 number.
5800
5801 @item
5802 Environment variable to clear/trash memory being freed.
5803
5804 @item
5805 Environment variable to control tracing of allocations and frees.
5806
5807 @item
5808 Environment variable to display allocated memory at normal program end.
5809
5810 @item
5811 Environment variable for filename for * IO-unit.
5812
5813 @item
5814 Environment variable for temporary file directory.
5815
5816 @item
5817 Environment variable forcing standard output to be line buffered (Unix).
5818
5819 @end itemize
5820
5821
5822 @c ---------------------------------------------------------------------
5823 @c GNU General Public License
5824 @c ---------------------------------------------------------------------
5825
5826 @include gpl_v3.texi
5827
5828
5829
5830 @c ---------------------------------------------------------------------
5831 @c GNU Free Documentation License
5832 @c ---------------------------------------------------------------------
5833
5834 @include fdl.texi
5835
5836
5837
5838 @c ---------------------------------------------------------------------
5839 @c Funding Free Software
5840 @c ---------------------------------------------------------------------
5841
5842 @include funding.texi
5843
5844 @c ---------------------------------------------------------------------
5845 @c Indices
5846 @c ---------------------------------------------------------------------
5847
5848 @node Option Index
5849 @unnumbered Option Index
5850 @command{gfortran}'s command line options are indexed here without any
5851 initial @samp{-} or @samp{--}. Where an option has both positive and
5852 negative forms (such as -foption and -fno-option), relevant entries in
5853 the manual are indexed under the most appropriate form; it may sometimes
5854 be useful to look up both forms.
5855 @printindex op
5856
5857 @node Keyword Index
5858 @unnumbered Keyword Index
5859 @printindex cp
5860
5861 @bye