📄 gfortran.texi
字号:
@samp{y}, @samp{Y} or @samp{1} (only the first letter is relevant)then library run-time errors cause core dumps. To disable the coredumps, set the variable to @samp{n}, @samp{N}, @samp{0}. Defaultis not to core dump unless the @option{-fdump-core} compile optionwas used.@node GFORTRAN_ERROR_BACKTRACE@section @env{GFORTRAN_ERROR_BACKTRACE}---Show backtrace on run-time errorsIf the @env{GFORTRAN_ERROR_BACKTRACE} variable is set to@samp{y}, @samp{Y} or @samp{1} (only the first letter is relevant)then a backtrace is printed when a run-time error occurs.To disable the backtracing, set the variable to@samp{n}, @samp{N}, @samp{0}. Default is not to print a backtraceunless the @option{-fbacktrace} compile optionwas used.@c =====================================================================@c PART II: LANGUAGE REFERENCE@c =====================================================================@tex\part{II}{Language Reference}@end tex@c ---------------------------------------------------------------------@c Fortran 2003 Status@c ---------------------------------------------------------------------@node Fortran 2003 status@chapter Fortran 2003 StatusAlthough GNU Fortran focuses on implementing the Fortran 95standard for the time being, a few Fortran 2003 features are currentlyavailable.@itemize@item Intrinsics @code{command_argument_count}, @code{get_command},@code{get_command_argument}, @code{get_environment_variable}, and@code{move_alloc}.@item @cindex array, constructors@cindex @code{[...]}Array constructors using square brackets. That is, @code{[...]} ratherthan @code{(/.../)}.@item@cindex @code{FLUSH} statement@cindex statement, @code{FLUSH}@code{FLUSH} statement.@item@cindex @code{IOMSG=} specifier@code{IOMSG=} specifier for I/O statements.@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.@item@cindex TR 15581TR 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@end itemize@item@cindex @code{STREAM} I/O@cindex @code{ACCESS='STREAM'} I/OThe @code{OPEN} statement supports the @code{ACCESS='STREAM'} specifier,allowing I/O without any record structure.@itemNamelist input/output for internal files.@item@cindex @code{PROTECTED} statement@cindex statement, @code{PROTECTED}The @code{PROTECTED} statement and attribute.@item@cindex @code{VALUE} statement@cindex statement, @code{VALUE}The @code{VALUE} statement and attribute.@item@cindex @code{VOLATILE} statement@cindex statement, @code{VOLATILE}The @code{VOLATILE} statement and attribute.@item@cindex @code{IMPORT} statement@cindex statement, @code{IMPORT}The @code{IMPORT} statement, allowing to importhost-associated derived types.@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{OMP_LIB} and @code{OMP_LIB_KINDS}.@itemRenaming of operators in the @code{USE} statement.@item@cindex ISO C BindingsInteroperability with C (ISO C Bindings)@itemBOZ as argument of INT, REAL, DBLE and CMPLX.@end itemize@c ---------------------------------------------------------------------@c Extensions@c ---------------------------------------------------------------------@c Maybe this chapter should be merged with the 'Standards' section,@c whenever that is written :-)@node Extensions@chapter Extensions@cindex extensionsThe two sections below detail the extensions to standard Fortran that areimplemented in GNU Fortran, as well as some of the popular orhistorically important extensions that are not (or not yet) implemented.For the latter case, we explain the alternatives available to GNU Fortranusers, including replacement by standard-conforming code or GNUextensions.@menu* Extensions implemented in GNU Fortran::* Extensions not implemented in GNU Fortran::@end menu@node Extensions implemented in GNU Fortran@section Extensions implemented in GNU Fortran@cindex extensions, implementedGNU Fortran implements a number of extensions over standardFortran. This chapter contains information on their syntax andmeaning. There are currently two categories of GNU Fortranextensions, those that provide functionality beyond that providedby any standard, and those that are supported by GNU Fortranpurely for backward compatibility with legacy compilers. By default,@option{-std=gnu} allows the compiler to accept both types ofextensions, but to warn about the use of the latter. Specifyingeither @option{-std=f95} or @option{-std=f2003} disables both typesof extensions, and @option{-std=legacy} allows both without warning.@menu* Old-style kind specifications::* Old-style variable initialization::* Extensions to namelist::* X format descriptor without count field::* Commas in FORMAT specifications::* Missing period in FORMAT specifications::* I/O item lists::* BOZ literal constants::* Real array indices::* Unary operators::* Implicitly convert LOGICAL and INTEGER values::* Hollerith constants support::* Cray pointers::* CONVERT specifier::* OpenMP::* Argument list functions::@end menu@node Old-style kind specifications@subsection Old-style kind specifications@cindex kind, old-styleGNU Fortran allows old-style kind specifications in declarations. Theselook like:@smallexample TYPESPEC*size x,y,z@end smallexample@noindentwhere @code{TYPESPEC} is a basic type (@code{INTEGER}, @code{REAL},etc.), and where @code{size} is a byte count corresponding to thestorage size of a valid kind for that type. (For @code{COMPLEX}variables, @code{size} is the total size of the real and imaginaryparts.) The statement then declares @code{x}, @code{y} and @code{z} tobe of type @code{TYPESPEC} with the appropriate kind. This isequivalent to the standard-conforming declaration@smallexample TYPESPEC(k) x,y,z@end smallexample@noindentwhere @code{k} is equal to @code{size} for most types, but is equal to@code{size/2} for the @code{COMPLEX} type.@node Old-style variable initialization@subsection Old-style variable initializationGNU Fortran allows old-style initialization of variables of theform:@smallexample INTEGER i/1/,j/2/ REAL x(2,2) /3*0.,1./@end smallexampleThe syntax for the initializers is as for the @code{DATA} statement, butunlike in a @code{DATA} statement, an initializer only applies to thevariable immediately preceding the initialization. In other words,something like @code{INTEGER I,J/2,3/} is not valid. This style ofinitialization is only allowed in declarations without double colons(@code{::}); the double colons were introduced in Fortran 90, which alsointroduced a standard syntax for initializing variables in typedeclarations.Examples of standard-conforming code equivalent to the above exampleare:@smallexample! Fortran 90 INTEGER :: i = 1, j = 2 REAL :: x(2,2) = RESHAPE((/0.,0.,0.,1./),SHAPE(x))! Fortran 77 INTEGER i, j REAL x(2,2) DATA i/1/, j/2/, x/3*0.,1./@end smallexampleNote that variables which are explicitly initialized in declarationsor in @code{DATA} statements automatically acquire the @code{SAVE}attribute.@node Extensions to namelist@subsection Extensions to namelist@cindex NamelistGNU Fortran fully supports the Fortran 95 standard for namelist I/Oincluding array qualifiers, substrings and fully qualified derived types.The output from a namelist write is compatible with namelist read. Theoutput has all names in upper case and indentation to column 1 after thenamelist name. Two extensions are permitted:Old-style use of @samp{$} instead of @samp{&}@smallexample$MYNML X(:)%Y(2) = 1.0 2.0 3.0 CH(1:4) = "abcd"$END@end smallexampleIt should be noted that the default terminator is @samp{/} rather than@samp{&END}.Querying of the namelist when inputting from stdin. After at leastone space, entering @samp{?} sends to stdout the namelist name and the names ofthe variables in the namelist:@smallexample ?&mynml x x%y ch&end@end smallexampleEntering @samp{=?} outputs the namelist to stdout, as if@code{WRITE(*,NML = mynml)} had been called:@smallexample=?&MYNML X(1)%Y= 0.000000 , 1.000000 , 0.000000 , X(2)%Y= 0.000000 , 2.000000 , 0.000000 , X(3)%Y= 0.000000 , 3.000000 , 0.000000 , CH=abcd, /@end smallexampleTo aid this dialog, when input is from stdin, errors send theirmessages to stderr and execution continues, even if @code{IOSTAT} is set.@code{PRINT} namelist is permitted. This causes an error if@option{-std=f95} is used.@smallexamplePROGRAM test_print REAL, dimension (4) :: x = (/1.0, 2.0, 3.0, 4.0/) NAMELIST /mynml/ x PRINT mynmlEND PROGRAM test_print@end smallexampleExpanded namelist reads are permitted. This causes an error if @option{-std=f95} is used. In the following example, the first elementof the array will be given the value 0.00 and the two succeedingelements will be given the values 1.00 and 2.00.@smallexample&MYNML X(1,1) = 0.00 , 1.00 , 2.00/@end smallexample@node X format descriptor without count field@subsection @code{X} format descriptor without count fieldTo support legacy codes, GNU Fortran permits the count field of the@code{X} edit descriptor in @code{FORMAT} statements to be omitted.When omitted, the count is implicitly assumed to be one.@smallexample PRINT 10, 2, 310 FORMAT (I1, X, I1)@end smallexample@node Commas in FORMAT specifications@subsection Commas in @code{FORMAT} specificationsTo support legacy codes, GNU Fortran allows the comma separatorto be omitted immediately before and after character string editdescriptors in @code{FORMAT} statements.@smallexample PRINT 10, 2, 310 FORMAT ('FOO='I1' BAR='I2)@end smallexample@node Missing period in FORMAT specifications@subsection Missing period in @code{FORMAT} specificationsTo support legacy codes, GNU Fortran allows missing periods in formatspecifications if and only if @option{-std=legacy} is given on thecommand line. This is considered non-conforming code and isdiscouraged.@smallexample REAL :: value READ(*,10) value10 FORMAT ('F4')@end smallexample@node I/O item lists@subsection I/O item lists@cindex I/O item listsTo support legacy codes, GNU Fortran allows the input item listof the @code{READ} statement, and the output item lists of the@code{WRITE} and @code{PRINT} statements, to start with a comma.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -