From 227e0100360b83e7981ef9b2ce85435bbc16ee82 Mon Sep 17 00:00:00 2001 From: Sandra Loosemore Date: Fri, 29 Oct 2021 15:08:47 -0700 Subject: [PATCH] Fortran manual: Revise introductory chapter. Fix various bit-rot in the discussion of standards conformance, remove material that is only of historical interest, copy-editing. Also move discussion of preprocessing out of the introductory chapter. 2021-11-01 Sandra Loosemore gcc/fortran/ * gfortran.texi (About GNU Fortran): Consolidate material formerly in other sections. Copy-editing. (Preprocessing and conditional compilation): Delete, moving most material to invoke.texi. (GNU Fortran and G77): Delete. (Project Status): Delete. (Standards): Update. (Fortran 95 status): Mention conditional compilation here. (Fortran 2003 status): Rewrite to mention the 1 missing feature instead of all the ones implemented. (Fortran 2008 status): Similarly for the 2 missing features. (Fortran 2018 status): Rewrite to reflect completion of TS29113 feature support. * invoke.texi (Preprocessing Options): Move material formerly in introductory chapter here. --- gcc/fortran/gfortran.texi | 627 +++++++++------------------------------------- gcc/fortran/invoke.texi | 44 +++- 2 files changed, 160 insertions(+), 511 deletions(-) diff --git a/gcc/fortran/gfortran.texi b/gcc/fortran/gfortran.texi index 26cf44f..ba5db57 100644 --- a/gcc/fortran/gfortran.texi +++ b/gcc/fortran/gfortran.texi @@ -219,17 +219,9 @@ compiler. @end ifset @end iftex -The GNU Fortran compiler front end was -designed initially as a free replacement for, -or alternative to, the Unix @command{f95} command; -@command{gfortran} is the command you will use to invoke the compiler. - @menu * About GNU Fortran:: What you should know about the GNU Fortran compiler. * GNU Fortran and GCC:: You can compile Fortran, C, or other programs. -* Preprocessing and conditional compilation:: The Fortran preprocessor -* GNU Fortran and G77:: Why we chose to start from scratch. -* Project Status:: Status of GNU Fortran, roadmap, proposed extensions. * Standards:: Standards supported by GNU Fortran. @end menu @@ -241,46 +233,67 @@ or alternative to, the Unix @command{f95} command; @node About GNU Fortran @section About GNU Fortran -The GNU Fortran compiler supports the Fortran 77, 90 and 95 standards -completely, parts of the Fortran 2003, 2008 and 2018 standards, and -several vendor extensions. The development goal is to provide the -following features: +The GNU Fortran compiler is the successor to @command{g77}, the +Fortran 77 front end included in GCC prior to version 4 (released in +2005). While it is backward-compatible with most @command{g77} +extensions and command-line options, @command{gfortran} is a completely new +implemention designed to support more modern dialects of Fortran. +GNU Fortran implements the Fortran 77, 90 and 95 standards +completely, most of the Fortran 2003 and 2008 standards, and some +features from the 2018 standard. It also implements several extensions +including OpenMP and OpenACC support for parallel programming. + +The GNU Fortran compiler passes the +@uref{http://www.fortran-2000.com/ArnaudRecipes/fcvs21_f95.html, +NIST Fortran 77 Test Suite}, and produces acceptable results on the +@uref{http://www.netlib.org/lapack/faq.html#1.21, LAPACK Test Suite}. +It also provides respectable performance on +the @uref{https://polyhedron.com/?page_id=175, +Polyhedron Fortran compiler benchmarks} and the +@uref{http://www.netlib.org/benchmark/livermore, +Livermore Fortran Kernels test}. It has been used to compile a number of +large real-world programs, including +@uref{http://hirlam.org/, the HARMONIE and HIRLAM weather forecasting code} and +@uref{https://github.com/dylan-jayatilaka/tonto, +the Tonto quantum chemistry package}; see +@url{https://gcc.gnu.org/@/wiki/@/GfortranApps} for an extended list. + +GNU Fortran provides the following functionality: @itemize @bullet @item -Read a user's program, stored in a file and containing instructions -written in Fortran 77, Fortran 90, Fortran 95, Fortran 2003, Fortran -2008 or Fortran 2018. This file contains @dfn{source code}. +Read a program, stored in a file and containing @dfn{source code} +instructions written in Fortran 77. @item -Translate the user's program into instructions a computer +Translate the program into instructions a computer can carry out more quickly than it takes to translate the -instructions in the first -place. The result after compilation of a program is +original Fortran instructions. +The result after compilation of a program is @dfn{machine code}, -code designed to be efficiently translated and processed +which is efficiently translated and processed by a machine such as your computer. Humans usually are not as good writing machine code as they are at writing Fortran (or C++, Ada, or Java), because it is easy to make tiny mistakes writing machine code. @item -Provide the user with information about the reasons why -the compiler is unable to create a binary from the source code. -Usually this will be the case if the source code is flawed. -The Fortran 90 standard requires that the compiler can point out -mistakes to the user. +Provide information about the reasons why +the compiler may be unable to create a binary from the source code, +for example if the source code is flawed. +The Fortran language standards require that the compiler can point out +mistakes in your code. An incorrect usage of the language causes an @dfn{error message}. -The compiler will also attempt to diagnose cases where the -user's program contains a correct usage of the language, +The compiler also attempts to diagnose cases where your +program contains a correct usage of the language, but instructs the computer to do something questionable. -This kind of diagnostics message is called a @dfn{warning message}. +This kind of diagnostic message is called a @dfn{warning message}. @item Provide optional information about the translation passes from the source code to machine code. -This can help a user of the compiler to find the cause of +This can help you to find the cause of certain bugs which may not be obvious in the source code, but may be more easily found at a lower level compiler output. It also helps developers to find bugs in the compiler itself. @@ -292,7 +305,7 @@ called a @dfn{debugger}, such as the GNU Debugger @command{gdb}). @item Locate and gather machine code already generated to -perform actions requested by statements in the user's program. +perform actions requested by statements in the program. This machine code is organized into @dfn{modules} and is located and @dfn{linked} to the user program. @end itemize @@ -316,8 +329,9 @@ which also might be installed as the system's @command{f95} command. @command{gfortran} is just another driver program, but specifically for the Fortran compiler only. -The difference with @command{gcc} is that @command{gfortran} -will automatically link the correct libraries to your program. +The primary difference between the @command{gcc} and @command{gfortran} +commands is that the latter automatically links the correct libraries +to your program. @item A collection of run-time libraries. @@ -338,7 +352,7 @@ linked to and interfaced with the GCC backend library. assembler code. You would typically not use this program directly; instead, the @command{gcc} or @command{gfortran} driver -programs will call it for you. +programs call it for you. @end itemize @@ -364,10 +378,10 @@ which provides the command-line interface for the compiler. It calls the relevant compiler front-end program (e.g., @command{f951} for Fortran) for each file in the source code, and then calls the assembler and linker as appropriate to produce the compiled output. In a copy of -GCC which has been compiled with Fortran language support enabled, -@command{gcc} will recognize files with @file{.f}, @file{.for}, @file{.ftn}, +GCC that has been compiled with Fortran language support enabled, +@command{gcc} recognizes files with @file{.f}, @file{.for}, @file{.ftn}, @file{.f90}, @file{.f95}, @file{.f03} and @file{.f08} extensions as -Fortran source code, and compile it accordingly. A @command{gfortran} +Fortran source code, and compiles it accordingly. A @command{gfortran} driver program is also provided, which is identical to @command{gcc} except that it automatically links the Fortran runtime libraries into the compiled program. @@ -382,138 +396,12 @@ extension are also run through preprocessing. This manual specifically documents the Fortran front end, which handles the programming language's syntax and semantics. The aspects of GCC -which relate to the optimization passes and the back-end code generation +that relate to the optimization passes and the back-end code generation are documented in the GCC manual; see @ref{Top,,Introduction,gcc,Using the GNU Compiler Collection (GCC)}. The two manuals together provide a complete reference for the GNU Fortran compiler. - -@c --------------------------------------------------------------------- -@c Preprocessing and conditional compilation -@c --------------------------------------------------------------------- - -@node Preprocessing and conditional compilation -@section Preprocessing and conditional compilation -@cindex CPP -@cindex FPP -@cindex Conditional compilation -@cindex Preprocessing -@cindex preprocessor, include file handling - -Many Fortran compilers including GNU Fortran allow passing the source code -through a C preprocessor (CPP; sometimes also called the Fortran preprocessor, -FPP) to allow for conditional compilation. In the case of GNU Fortran, -this is the GNU C Preprocessor in the traditional mode. On systems with -case-preserving file names, the preprocessor is automatically invoked if the -filename extension is @file{.F}, @file{.FOR}, @file{.FTN}, @file{.fpp}, -@file{.FPP}, @file{.F90}, @file{.F95}, @file{.F03} or @file{.F08}. To manually -invoke the preprocessor on any file, use @option{-cpp}, to disable -preprocessing on files where the preprocessor is run automatically, use -@option{-nocpp}. - -If a preprocessed file includes another file with the Fortran @code{INCLUDE} -statement, the included file is not preprocessed. To preprocess included -files, use the equivalent preprocessor statement @code{#include}. - -If GNU Fortran invokes the preprocessor, @code{__GFORTRAN__} -is defined. The macros @code{__GNUC__}, @code{__GNUC_MINOR__} and -@code{__GNUC_PATCHLEVEL__} can be used to determine the version of the -compiler. See @ref{Top,,Overview,cpp,The C Preprocessor} for details. - -GNU Fortran supports a number of @code{INTEGER} and @code{REAL} kind types -in additional to the kind types required by the Fortran standard. -The availability of any given kind type is architecture dependent. The -following pre-defined preprocessor macros can be used to conditionally -include code for these additional kind types: @code{__GFC_INT_1__}, -@code{__GFC_INT_2__}, @code{__GFC_INT_8__}, @code{__GFC_INT_16__}, -@code{__GFC_REAL_10__}, and @code{__GFC_REAL_16__}. - -While CPP is the de-facto standard for preprocessing Fortran code, -Part 3 of the Fortran 95 standard (ISO/IEC 1539-3:1998) defines -Conditional Compilation, which is not widely used and not directly -supported by the GNU Fortran compiler. You can use the program coco -to preprocess such files (@uref{http://www.daniellnagle.com/coco.html}). - - -@c --------------------------------------------------------------------- -@c GNU Fortran and G77 -@c --------------------------------------------------------------------- - -@node GNU Fortran and G77 -@section GNU Fortran and G77 -@cindex Fortran 77 -@cindex @command{g77} - -The GNU Fortran compiler is the successor to @command{g77}, the Fortran -77 front end included in GCC prior to version 4. It is an entirely new -program that has been designed to provide Fortran 95 support and -extensibility for future Fortran language standards, as well as providing -backwards compatibility for Fortran 77 and nearly all of the GNU language -extensions supported by @command{g77}. - - -@c --------------------------------------------------------------------- -@c Project Status -@c --------------------------------------------------------------------- - -@node Project Status -@section Project Status - -@quotation -As soon as @command{gfortran} can parse all of the statements correctly, -it will be in the ``larva'' state. -When we generate code, the ``puppa'' state. -When @command{gfortran} is done, -we'll see if it will be a beautiful butterfly, -or just a big bug.... - ---Andy Vaught, April 2000 -@end quotation - -The start of the GNU Fortran 95 project was announced on -the GCC homepage in March 18, 2000 -(even though Andy had already been working on it for a while, -of course). - -The GNU Fortran compiler is able to compile nearly all -standard-compliant Fortran 95, Fortran 90, and Fortran 77 programs, -including a number of standard and non-standard extensions, and can be -used on real-world programs. In particular, the supported extensions -include OpenMP, Cray-style pointers, some old vendor extensions, and several -Fortran 2003 and Fortran 2008 features, including TR 15581. However, it is -still under development and has a few remaining rough edges. -There also is initial support for OpenACC. - -At present, the GNU Fortran compiler passes the -@uref{http://www.fortran-2000.com/ArnaudRecipes/fcvs21_f95.html, -NIST Fortran 77 Test Suite}, and produces acceptable results on the -@uref{http://www.netlib.org/lapack/faq.html#1.21, LAPACK Test Suite}. -It also provides respectable performance on -the @uref{http://www.polyhedron.com/fortran-compiler-comparisons/polyhedron-benchmark-suite, -Polyhedron Fortran -compiler benchmarks} and the -@uref{http://www.netlib.org/benchmark/livermore, -Livermore Fortran Kernels test}. It has been used to compile a number of -large real-world programs, including -@uref{http://hirlam.org/, the HARMONIE and HIRLAM weather forecasting code} and -@uref{http://physical-chemistry.scb.uwa.edu.au/tonto/wiki/index.php/Main_Page, -the Tonto quantum chemistry package}; see -@url{https://gcc.gnu.org/@/wiki/@/GfortranApps} for an extended list. - -Among other things, the GNU Fortran compiler is intended as a replacement -for G77. At this point, nearly all programs that could be compiled with -G77 can be compiled with GNU Fortran, although there are a few minor known -regressions. - -The primary work remaining to be done on GNU Fortran falls into three -categories: bug fixing (primarily regarding the treatment of invalid -code and providing useful error messages), improving the compiler -optimizations and the performance of compiled code, and extending the -compiler to support future standards---in particular, Fortran 2003, -Fortran 2008 and Fortran 2018. - - @c --------------------------------------------------------------------- @c Standards @c --------------------------------------------------------------------- @@ -529,18 +417,27 @@ Fortran 2008 and Fortran 2018. * Fortran 2018 status:: @end menu -The GNU Fortran compiler implements -ISO/IEC 1539:1997 (Fortran 95). As such, it can also compile essentially all -standard-compliant Fortran 90 and Fortran 77 programs. It also supports -the ISO/IEC TR-15581 enhancements to allocatable arrays. - -GNU Fortran also have a partial support for ISO/IEC 1539-1:2004 -(Fortran 2003), ISO/IEC 1539-1:2010 (Fortran 2008), the Technical -Specification @code{Further Interoperability of Fortran with C} -(ISO/IEC TS 29113:2012). Full support of those standards and future -Fortran standards is planned. The current status of the support is -can be found in the @ref{Fortran 2003 status}, @ref{Fortran 2008 -status} and @ref{Fortran 2018 status} sections of the documentation. +Fortran is developed by the Working Group 5 of Sub-Committee 22 of the +Joint Technical Committee 1 of the International Organization for +Standardization and the International Electrotechnical Commission (IEC). +This group is known as @uref{http://www.nag.co.uk/sc22wg5/, WG5}. +Official Fortran standard documents are available for purchase +from ISO; a collection of free documents (typically final drafts) are +also available on the @uref{https://gcc.gnu.org/wiki/GFortranStandards, wiki}. + +The GNU Fortran compiler implements ISO/IEC 1539:1997 (Fortran 95). +As such, it can also compile essentially all standard-compliant +Fortran 90 and Fortran 77 programs. It also supports the ISO/IEC +TR-15581 enhancements to allocatable arrays. + +GNU Fortran also supports almost all of ISO/IEC 1539-1:2004 +(Fortran 2003) and ISO/IEC 1539-1:2010 (Fortran 2008). +It has partial support for features introduced in ISO/IEC +1539:2018 (Fortran 2018), the most recent version of the Fortran +language standard, including full support for the Technical Specification +@code{Further Interoperability of Fortran with C} (ISO/IEC TS 29113:2012). +More details on support for these standards can be +found in the following sections of the documentation. Additionally, the GNU Fortran compilers supports the OpenMP specification (version 4.5 and partial support of the features of the 5.0 version, @@ -551,9 +448,9 @@ version 2.6, @uref{http://www.openacc.org/}). See @node Fortran 95 status @subsection Fortran 95 status -@cindex Varying length character strings @cindex Varying length strings @cindex strings, varying length +@cindex conditional compilation The Fortran 95 standard specifies in Part 2 (ISO/IEC 1539-2:2000) varying length character strings. While GNU Fortran currently does not @@ -567,377 +464,93 @@ the features of @code{ISO_VARYING_STRING} and should be considered as replacement. (Namely, allocatable or pointers of the type @code{character(len=:)}.) +Part 3 of the Fortran 95 standard (ISO/IEC 1539-3:1998) defines +Conditional Compilation, which is not widely used and not directly +supported by the GNU Fortran compiler. You can use the program coco +to preprocess such files (@uref{http://www.daniellnagle.com/coco.html}). + @node Fortran 2003 status @subsection Fortran 2003 status -GNU Fortran supports several Fortran 2003 features; an incomplete -list can be found below. See also the -@uref{https://gcc.gnu.org/wiki/Fortran2003, wiki page} about Fortran 2003. - -@itemize -@item Procedure pointers including procedure-pointer components with -@code{PASS} attribute. - -@item Procedures which are bound to a derived type (type-bound procedures) -including @code{PASS}, @code{PROCEDURE} and @code{GENERIC}, and -operators bound to a type. - -@item Abstract interfaces and type extension with the possibility to -override type-bound procedures or to have deferred binding. - -@item Polymorphic entities (``@code{CLASS}'') for derived types and unlimited -polymorphism (``@code{CLASS(*)}'') -- including @code{SAME_TYPE_AS}, -@code{EXTENDS_TYPE_OF} and @code{SELECT TYPE} for scalars and arrays and -finalization. - -@item Generic interface names, which have the same name as derived types, -are now supported. This allows one to write constructor functions. Note -that Fortran does not support static constructor functions. For static -variables, only default initialization or structure-constructor -initialization are available. - -@item The @code{ASSOCIATE} construct. - -@item Interoperability with C including enumerations, - -@item In structure constructors the components with default values may be -omitted. - -@item Extensions to the @code{ALLOCATE} statement, allowing for a -type-specification with type parameter and for allocation and initialization -from a @code{SOURCE=} expression; @code{ALLOCATE} and @code{DEALLOCATE} -optionally return an error message string via @code{ERRMSG=}. +GNU Fortran implements the Fortran 2003 (ISO/IEC 1539-1:2004) standard +except for finalization support, which is incomplete. +See the +@uref{https://gcc.gnu.org/wiki/Fortran2003, wiki page} for a full list +of new features introduced by Fortran 2003 and their implementation status. -@item Reallocation on assignment: If an intrinsic assignment is -used, an allocatable variable on the left-hand side is automatically allocated -(if unallocated) or reallocated (if the shape is different). Currently, scalar -deferred character length left-hand sides are correctly handled but arrays -are not yet fully implemented. - -@item Deferred-length character variables and scalar deferred-length character -components of derived types are supported. (Note that array-valued components -are not yet implemented.) - -@item Transferring of allocations via @code{MOVE_ALLOC}. - -@item The @code{PRIVATE} and @code{PUBLIC} attributes may be given individually -to derived-type components. - -@item In pointer assignments, the lower bound may be specified and -the remapping of elements is supported. - -@item For pointers an @code{INTENT} may be specified which affect the -association status not the value of the pointer target. - -@item Intrinsics @code{command_argument_count}, @code{get_command}, -@code{get_command_argument}, and @code{get_environment_variable}. - -@item Support for Unicode characters (ISO 10646) and UTF-8, including -the @code{SELECTED_CHAR_KIND} and @code{NEW_LINE} intrinsic functions. - -@item Support for binary, octal and hexadecimal (BOZ) constants in the -intrinsic functions @code{INT}, @code{REAL}, @code{CMPLX} and @code{DBLE}. - -@item Support for namelist variables with allocatable and pointer -attribute and nonconstant length type parameter. - -@item -@cindex array, constructors -@cindex @code{[...]} -Array constructors using square brackets. That is, @code{[...]} rather -than @code{(/.../)}. Type-specification for array constructors like -@code{(/ some-type :: ... /)}. - -@item Extensions to the specification and initialization expressions, -including the support for intrinsics with real and complex arguments. - -@item Support for the asynchronous input/output. - -@item -@cindex @code{FLUSH} statement -@cindex statement, @code{FLUSH} -@code{FLUSH} statement. +@node Fortran 2008 status +@subsection Fortran 2008 status -@item -@cindex @code{IOMSG=} specifier -@code{IOMSG=} specifier for I/O statements. +The GNU Fortran compiler supports almost all features of Fortran 2008; +the @uref{https://gcc.gnu.org/wiki/Fortran2008Status, wiki} +has some information about the current implementation status. +In particular, the following are not yet supported: +@itemize @bullet @item -@cindex @code{ENUM} statement -@cindex @code{ENUMERATOR} statement -@cindex statement, @code{ENUM} -@cindex statement, @code{ENUMERATOR} -@opindex @code{fshort-enums} -Support for the declaration of enumeration constants via the -@code{ENUM} and @code{ENUMERATOR} statements. Interoperability with -@command{gcc} is guaranteed also for the case where the -@command{-fshort-enums} command line option is given. +@code{DO CONCURRENT} and @code{FORALL} do not recognize a +type-spec in the loop header. @item -@cindex TR 15581 -TR 15581: -@itemize -@item -@cindex @code{ALLOCATABLE} dummy arguments -@code{ALLOCATABLE} dummy arguments. -@item -@cindex @code{ALLOCATABLE} function results -@code{ALLOCATABLE} function results -@item -@cindex @code{ALLOCATABLE} components of derived types -@code{ALLOCATABLE} components of derived types +The change to permit any constant expression in subscripts and +nested implied-do limits in a @code{DATA} statement has not been implemented. @end itemize -@item -@cindex @code{STREAM} I/O -@cindex @code{ACCESS='STREAM'} I/O -The @code{OPEN} statement supports the @code{ACCESS='STREAM'} specifier, -allowing I/O without any record structure. -@item -Namelist input/output for internal files. +@node Fortran 2018 status +@subsection Fortran 2018 status -@item Minor I/O features: Rounding during formatted output, using of -a decimal comma instead of a decimal point, setting whether a plus sign -should appear for positive numbers. On systems where @code{strtod} honours -the rounding mode, the rounding mode is also supported for input. +Fortran 2018 (ISO/IEC 1539:2018) is the most recent version +of the Fortran language standard. GNU Fortran implements some of the +new features of this standard: +@itemize @bullet @item -@cindex @code{PROTECTED} statement -@cindex statement, @code{PROTECTED} -The @code{PROTECTED} statement and attribute. +All Fortran 2018 features derived from ISO/IEC TS 29113:2012, +``Further Interoperability of Fortran with C'', are supported by GNU Fortran. +This includes assumed-type and assumed-rank objects and +the @code{SELECT RANK} construct as well as the parts relating to +@code{BIND(C)} functions. +See also @ref{Further Interoperability of Fortran with C}. @item -@cindex @code{VALUE} statement -@cindex statement, @code{VALUE} -The @code{VALUE} statement and attribute. +GNU Fortran supports a subset of features derived from ISO/IEC TS 18508:2015, +``Additional Parallel Features in Fortran'': +@itemize @bullet @item -@cindex @code{VOLATILE} statement -@cindex statement, @code{VOLATILE} -The @code{VOLATILE} statement and attribute. +The new atomic ADD, CAS, FETCH and ADD/OR/XOR, OR and XOR intrinsics. @item -@cindex @code{IMPORT} statement -@cindex statement, @code{IMPORT} -The @code{IMPORT} statement, allowing to import -host-associated derived types. - -@item The intrinsic modules @code{ISO_FORTRAN_ENVIRONMENT} is supported, -which contains parameters of the I/O units, storage sizes. Additionally, -procedures for C interoperability are available in the @code{ISO_C_BINDING} -module. +The @code{CO_MIN} and @code{CO_MAX} and @code{SUM} reduction intrinsics, +and the @code{CO_BROADCAST} and @code{CO_REDUCE} intrinsic, except that those +do not support polymorphic types or types with allocatable, pointer or +polymorphic components. @item -@cindex @code{USE, INTRINSIC} statement -@cindex statement, @code{USE, INTRINSIC} -@cindex @code{ISO_FORTRAN_ENV} statement -@cindex statement, @code{ISO_FORTRAN_ENV} -@code{USE} statement with @code{INTRINSIC} and @code{NON_INTRINSIC} -attribute; supported intrinsic modules: @code{ISO_FORTRAN_ENV}, -@code{ISO_C_BINDING}, @code{OMP_LIB} and @code{OMP_LIB_KINDS}, -and @code{OPENACC}. +Events (@code{EVENT POST}, @code{EVENT WAIT}, @code{EVENT_QUERY}). @item -Renaming of operators in the @code{USE} statement. +Failed images (@code{FAIL IMAGE}, @code{IMAGE_STATUS}, +@code{FAILED_IMAGES}, @code{STOPPED_IMAGES}). @end itemize - -@node Fortran 2008 status -@subsection Fortran 2008 status - -The latest version of the Fortran standard is ISO/IEC 1539-1:2010, informally -known as Fortran 2008. The official version is available from International -Organization for Standardization (ISO) or its national member organizations. -The the final draft (FDIS) can be downloaded free of charge from -@url{http://www.nag.co.uk/@/sc22wg5/@/links.html}. Fortran is developed by the -Working Group 5 of Sub-Committee 22 of the Joint Technical Committee 1 of the -International Organization for Standardization and the International -Electrotechnical Commission (IEC). This group is known as -@uref{http://www.nag.co.uk/sc22wg5/, WG5}. - -The GNU Fortran compiler supports several of the new features of Fortran 2008; -the @uref{https://gcc.gnu.org/wiki/Fortran2008Status, wiki} has some information -about the current Fortran 2008 implementation status. In particular, the -following is implemented. - -@itemize -@item The @option{-std=f2008} option and support for the file extensions -@file{.f08} and @file{.F08}. - -@item The @code{OPEN} statement now supports the @code{NEWUNIT=} option, -which returns a unique file unit, thus preventing inadvertent use of the -same unit in different parts of the program. - -@item The @code{g0} format descriptor and unlimited format items. - -@item The mathematical intrinsics @code{ASINH}, @code{ACOSH}, @code{ATANH}, -@code{ERF}, @code{ERFC}, @code{GAMMA}, @code{LOG_GAMMA}, @code{BESSEL_J0}, -@code{BESSEL_J1}, @code{BESSEL_JN}, @code{BESSEL_Y0}, @code{BESSEL_Y1}, -@code{BESSEL_YN}, @code{HYPOT}, @code{NORM2}, and @code{ERFC_SCALED}. - -@item Using complex arguments with @code{TAN}, @code{SINH}, @code{COSH}, -@code{TANH}, @code{ASIN}, @code{ACOS}, and @code{ATAN} is now possible; -@code{ATAN}(@var{Y},@var{X}) is now an alias for @code{ATAN2}(@var{Y},@var{X}). - -@item Support of the @code{PARITY} intrinsic functions. - -@item The following bit intrinsics: @code{LEADZ} and @code{TRAILZ} for -counting the number of leading and trailing zero bits, @code{POPCNT} and -@code{POPPAR} for counting the number of one bits and returning the parity; -@code{BGE}, @code{BGT}, @code{BLE}, and @code{BLT} for bitwise comparisons; -@code{DSHIFTL} and @code{DSHIFTR} for combined left and right shifts, -@code{MASKL} and @code{MASKR} for simple left and right justified masks, -@code{MERGE_BITS} for a bitwise merge using a mask, @code{SHIFTA}, -@code{SHIFTL} and @code{SHIFTR} for shift operations, and the -transformational bit intrinsics @code{IALL}, @code{IANY} and @code{IPARITY}. - -@item Support of the @code{EXECUTE_COMMAND_LINE} intrinsic subroutine. - -@item Support for the @code{STORAGE_SIZE} intrinsic inquiry function. - -@item The @code{INT@{8,16,32@}} and @code{REAL@{32,64,128@}} kind type -parameters and the array-valued named constants @code{INTEGER_KINDS}, -@code{LOGICAL_KINDS}, @code{REAL_KINDS} and @code{CHARACTER_KINDS} of -the intrinsic module @code{ISO_FORTRAN_ENV}. - -@item The module procedures @code{C_SIZEOF} of the intrinsic module -@code{ISO_C_BINDINGS} and @code{COMPILER_VERSION} and @code{COMPILER_OPTIONS} -of @code{ISO_FORTRAN_ENV}. - -@item Coarray support for serial programs with @option{-fcoarray=single} flag -and experimental support for multiple images with the @option{-fcoarray=lib} -flag. - -@item Submodules are supported. It should noted that @code{MODULEs} do not -produce the smod file needed by the descendent @code{SUBMODULEs} unless they -contain at least one @code{MODULE PROCEDURE} interface. The reason for this is -that @code{SUBMODULEs} are useless without @code{MODULE PROCEDUREs}. See -http://j3-fortran.org/doc/meeting/207/15-209.txt for a discussion and a draft -interpretation. Adopting this interpretation has the advantage that code that -does not use submodules does not generate smod files. - -@item The @code{DO CONCURRENT} construct is supported. - -@item The @code{BLOCK} construct is supported. - -@item The @code{STOP} and the new @code{ERROR STOP} statements now -support all constant expressions. Both show the signals which were signaling -at termination. - -@item Support for the @code{CONTIGUOUS} attribute. - -@item Support for @code{ALLOCATE} with @code{MOLD}. - -@item Support for the @code{IMPURE} attribute for procedures, which -allows for @code{ELEMENTAL} procedures without the restrictions of -@code{PURE}. - -@item Null pointers (including @code{NULL()}) and not-allocated variables -can be used as actual argument to optional non-pointer, non-allocatable -dummy arguments, denoting an absent argument. - -@item Non-pointer variables with @code{TARGET} attribute can be used as -actual argument to @code{POINTER} dummies with @code{INTENT(IN)}. - -@item Pointers including procedure pointers and those in a derived -type (pointer components) can now be initialized by a target instead -of only by @code{NULL}. - -@item The @code{EXIT} statement (with construct-name) can be now be -used to leave not only the @code{DO} but also the @code{ASSOCIATE}, -@code{BLOCK}, @code{IF}, @code{SELECT CASE} and @code{SELECT TYPE} -constructs. - -@item Internal procedures can now be used as actual argument. - -@item Minor features: obsolesce diagnostics for @code{ENTRY} with -@option{-std=f2008}; a line may start with a semicolon; for internal -and module procedures @code{END} can be used instead of -@code{END SUBROUTINE} and @code{END FUNCTION}; @code{SELECTED_REAL_KIND} -now also takes a @code{RADIX} argument; intrinsic types are supported -for @code{TYPE}(@var{intrinsic-type-spec}); multiple type-bound procedures -can be declared in a single @code{PROCEDURE} statement; implied-shape -arrays are supported for named constants (@code{PARAMETER}). -@end itemize - - - -@node Fortran 2018 status -@subsection Status of Fortran 2018 support - -@itemize -@item ERROR STOP in a PURE procedure +@item An @code{ERROR STOP} statement is permitted in a @code{PURE} procedure. -@item IMPLICIT NONE with a spec-list -Support the @code{IMPLICIT NONE} statement with an +@item +GNU Fortran supports the @code{IMPLICIT NONE} statement with an @code{implicit-none-spec-list}. -@item Behavior of INQUIRE with the RECL= specifier - +@item The behavior of the @code{INQUIRE} statement with the @code{RECL=} specifier now conforms to Fortran 2018. @end itemize -@subsubsection TS 29113 Status (Further Interoperability with C) - -GNU Fortran supports some of the new features of the Technical -Specification (TS) 29113 on Further Interoperability of Fortran with C. -The @uref{https://gcc.gnu.org/wiki/TS29113Status, wiki} has some information -about the current TS 29113 implementation status. In particular, the -following is implemented. - -See also @ref{Further Interoperability of Fortran with C}. - -@itemize -@item The @code{OPTIONAL} attribute is allowed for dummy arguments -of @code{BIND(C) procedures.} - -@item The @code{RANK} intrinsic is supported. - -@item GNU Fortran's implementation for variables with @code{ASYNCHRONOUS} -attribute is compatible with TS 29113. - -@item Assumed types (@code{TYPE(*)}). - -@item Assumed-rank (@code{DIMENSION(..)}). - -@item ISO_Fortran_binding (now in Fortran 2018 18.4) is implemented such that -conversion of the array descriptor for assumed type or assumed rank arrays is -done in the library. The include file ISO_Fortran_binding.h is can be found in -@code{~prefix/lib/gcc/$target/$version}. -@end itemize - - - -@subsubsection TS 18508 Status (Additional Parallel Features) - -GNU Fortran supports the following new features of the Technical -Specification 18508 on Additional Parallel Features in Fortran: - -@itemize -@item The new atomic ADD, CAS, FETCH and ADD/OR/XOR, OR and XOR intrinsics. - -@item The @code{CO_MIN} and @code{CO_MAX} and @code{SUM} reduction intrinsics. -And the @code{CO_BROADCAST} and @code{CO_REDUCE} intrinsic, except that those -do not support polymorphic types or types with allocatable, pointer or -polymorphic components. - -@item Events (@code{EVENT POST}, @code{EVENT WAIT}, @code{EVENT_QUERY}) - -@item Failed images (@code{FAIL IMAGE}, @code{IMAGE_STATUS}, -@code{FAILED_IMAGES}, @code{STOPPED_IMAGES}) - -@end itemize - - - - @c ===================================================================== @c PART I: INVOCATION REFERENCE @c ===================================================================== diff --git a/gcc/fortran/invoke.texi b/gcc/fortran/invoke.texi index 0fb7e1a..3533e86 100644 --- a/gcc/fortran/invoke.texi +++ b/gcc/fortran/invoke.texi @@ -570,10 +570,46 @@ Enhance test coverage by forcing most forall assignments to use temporary. @cindex preprocessor @cindex options, preprocessor @cindex CPP - -Preprocessor related options. See section -@ref{Preprocessing and conditional compilation} for more detailed -information on preprocessing in @command{gfortran}. +@cindex FPP +@cindex Conditional compilation +@cindex Preprocessing +@cindex preprocessor, include file handling + +Many Fortran compilers including GNU Fortran allow passing the source code +through a C preprocessor (CPP; sometimes also called the Fortran preprocessor, +FPP) to allow for conditional compilation. In the case of GNU Fortran, +this is the GNU C Preprocessor in the traditional mode. On systems with +case-preserving file names, the preprocessor is automatically invoked if the +filename extension is @file{.F}, @file{.FOR}, @file{.FTN}, @file{.fpp}, +@file{.FPP}, @file{.F90}, @file{.F95}, @file{.F03} or @file{.F08}. To manually +invoke the preprocessor on any file, use @option{-cpp}, to disable +preprocessing on files where the preprocessor is run automatically, use +@option{-nocpp}. + +If a preprocessed file includes another file with the Fortran @code{INCLUDE} +statement, the included file is not preprocessed. To preprocess included +files, use the equivalent preprocessor statement @code{#include}. + +If GNU Fortran invokes the preprocessor, @code{__GFORTRAN__} +is defined. The macros @code{__GNUC__}, @code{__GNUC_MINOR__} and +@code{__GNUC_PATCHLEVEL__} can be used to determine the version of the +compiler. See @ref{Top,,Overview,cpp,The C Preprocessor} for details. + +GNU Fortran supports a number of @code{INTEGER} and @code{REAL} kind types +in additional to the kind types required by the Fortran standard. +The availability of any given kind type is architecture dependent. The +following pre-defined preprocessor macros can be used to conditionally +include code for these additional kind types: @code{__GFC_INT_1__}, +@code{__GFC_INT_2__}, @code{__GFC_INT_8__}, @code{__GFC_INT_16__}, +@code{__GFC_REAL_10__}, and @code{__GFC_REAL_16__}. + +While CPP is the de-facto standard for preprocessing Fortran code, +Part 3 of the Fortran 95 standard (ISO/IEC 1539-3:1998) defines +Conditional Compilation, which is not widely used and not directly +supported by the GNU Fortran compiler. You can use the program coco +to preprocess such files (@uref{http://www.daniellnagle.com/coco.html}). + +The following options control preprocessing of Fortran code: @table @gcctabopt @item -cpp -- 2.7.4