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