GNU Fortran supports a variety of features that are not
considered part of the GNU Fortran language itself, but
are representative of various dialects of Fortran that
g77
supports in whole or in part.
Any of the features listed below might be disallowed by
g77
unless some command-line option is specified.
Currently, some of the features are accepted using the
default invocation of g77
, but that might change
in the future.
Note: This portion of the documentation definitely needs a lot of work!
GNU Fortran accepts programs written in either fixed form or free form.
Fixed form corresponds to ANSI FORTRAN 77 (plus popular extensions, such as allowing tabs) and Fortran 90's fixed form.
Free form corresponds to Fortran 90's free form (though possibly not entirely up-to-date, and without complaining about some things that for which Fortran 90 requires diagnostics, such as the spaces in the constant in `R = 3 . 1').
The way a Fortran compiler views source files depends entirely on the
implementation choices made for the compiler, since those choices
are explicitly left to the implementation by the published Fortran
standards.
GNU Fortran currently tries to be somewhat like a few popular compilers
(f2c
, Digital ("DEC") Fortran, and so on), though a cleaner default
definition along with more
flexibility offered by command-line options is likely to be offered
in version 0.6.
This section describes how g77
interprets source lines.
Carriage returns (`\r') in source lines are ignored.
This is somewhat different from f2c
, which seems to treat them as
spaces outside character/Hollerith constants, and encodes them as `\r'
inside such constants.
A source line with a TAB character anywhere in it is treated as
entirely significant--however long it is--instead of ending in
column 72 (for fixed-form source) or 132 (for free-form source).
This also is different from f2c
, which encodes tabs as
`\t' (the ASCII TAB character) inside character
and Hollerith constants, but nevertheless seems to treat the column
position as if it had been affected by the canonical tab positioning.
g77
effectively
translates tabs to the appropriate number of spaces (a la the default
for the UNIX expand
command) before doing any other processing, other
than (currently) noting whether a tab was found on a line and using this
information to decide how to interpret the length of the line and continued
constants.
Note that this default behavior probably will change for version 0.6, when it will presumably be available via a command-line option. The default as of version 0.6 is planned to be a "pure visual" model, where tabs are immediately converted to spaces and otherwise have no effect, so the way a typical user sees source lines produces a consistent result no matter how the spacing in those source lines is actually implemented via tabs, spaces, and trailing tabs/spaces before newline. Command-line options are likely to be added to specify whether all or just-tabbed lines are to be extended to 132 or full input-line length, and perhaps even an option will be added to specify the truncated-line behavior to which some Digital compilers default (and which affects the way continued character/Hollerith constants are interpreted).
Source lines shorter than the applicable fixed-form length are treated as if they were padded with spaces to that length. (None of this is relevant to source files written in free form.)
This affects only continued character and Hollerith constants, and is a different interpretation than provided by some other popular compilers (although a bit more consistent with the traditional punched-card basis of Fortran and the way the Fortran standard expressed fixed source form).
g77
might someday offer an option to warn about cases where differences
might be seen as a result of this treatment, and perhaps an option to
specify the alternate behavior as well.
Note that this padding cannot apply to lines that are effectively of infinite length--such lines are specified using command-line options like `-ffixed-line-length-none', for example.
Source lines longer than the applicable length are truncated to that
length.
Currently, g77
does not warn if the truncated characters are
not spaces, to accommodate existing code written for systems that
treated truncated text as commentary (especially in columns 73 through 80).
See section Options Controlling Fortran Dialect, for information on the `-ffixed-line-length-n' option, which can be used to set the line length applicable to fixed-form source files.
A `&' in column 1 of fixed-form source denotes an arbitrary-length
continuation line, imitating the behavior of f2c
.
g77
supports use of `/*' to start a trailing
comment.
In the GNU Fortran language, `!' is used for this purpose.
`/*' is not in the GNU Fortran language because the use of `/*' in a program might suggest to some readers that a block, not trailing, comment is started (and thus ended by `*/', not end of line), since that is the meaning of `/*' in C.
Also, such readers might think they can use `//' to start a trailing comment as an alternative to `/*', but `//' already denotes concatenation, and such a "comment" might actually result in a program that compiles without error (though it would likely behave incorrectly).
Use of `D' or `d' as the first character (column 1) of a source line denotes a debug line.
In turn, a debug line is treated as either a comment line or a normal line, depending on whether debug lines are enabled.
When treated as a comment line, a line beginning with `D' or `d' is treated as if it the first character was `C' or `c', respectively. When treated as a normal line, such a line is treated as if the first character was SPC (space).
(Currently, g77
provides no means for treating debug
lines as normal lines.)
Dollar signs (`$') are allowed in symbol names (after the first character) when the `-fdollar-ok' option is specified.
GNU Fortran offers the programmer way too much flexibility in deciding how source files are to be treated vis-a-vis uppercase and lowercase characters. There are 66 useful settings that affect case sensitivity, plus 10 settings that are nearly useless, with the remaining 116 settings being either redundant or useless.
None of these settings have any effect on the contents of comments (the text after a `c' or `C' in Column 1, for example) or of character or Hollerith constants. Note that things like the `E' in the statement `CALL FOO(3.2E10)' and the `TO' in `ASSIGN 10 TO LAB' are considered built-in keywords, and so are affected by these settings.
Low-level switches are identified in this section as follows:
Note 1: g77
eventually will support NAMELIST
in a manner that is
consistent with these source switches--in the sense that input will be
expected to meet the same requirements as source code in terms
of matching symbol names and keywords (for the exponent letters).
Currently, however, NAMELIST
is supported by libg2c
,
which uppercases NAMELIST
input and symbol names for matching.
This means not only that NAMELIST
output currently shows symbol
(and keyword) names in uppercase even if lower-case source
conversion (option A2) is selected, but that NAMELIST
cannot be
adequately supported when source case preservation (option A0)
is selected.
If A0 is selected, a warning message will be
output for each NAMELIST
statement to this effect.
The behavior
of the program is undefined at run time if two or more symbol names
appear in a given NAMELIST
such that the names are identical
when converted to upper case (e.g. `NAMELIST /X/ VAR, Var, var').
For complete and total elegance, perhaps there should be a warning
when option A2 is selected, since the output of NAMELIST is currently
in uppercase but will someday be lowercase (when a libg77
is written),
but that seems to be overkill for a product in beta test.
Note 2: Rules for InitialCaps names are:
So `A', `Ab', `ABc', `AbC', and `Abc' are
valid InitialCaps names, but `AB', `A2', and `ABC' are
not.
Note that most, but not all, built-in names meet these
requirements--the exceptions are some of the two-letter format
specifiers, such as BN
and BZ
.
Here are the names of the corresponding command-line options:
A0: -fsource-case-preserve A1: -fsource-case-upper A2: -fsource-case-lower B0: -fmatch-case-any B1: -fmatch-case-upper B2: -fmatch-case-lower B3: -fmatch-case-initcap C0: -fintrin-case-any C1: -fintrin-case-upper C2: -fintrin-case-lower C3: -fintrin-case-initcap D0: -fsymbol-case-any D1: -fsymbol-case-upper D2: -fsymbol-case-lower D3: -fsymbol-case-initcap
Useful combinations of the above settings, along with abbreviated option names that set some of these combinations all at once:
1: A0-- B0-- C0-- D0-- -fcase-preserve 2: A0-- B0-- C0-- D-1-- 3: A0-- B0-- C0-- D--2- 4: A0-- B0-- C0-- D--3 5: A0-- B0-- C-1-- D0--- 6: A0-- B0-- C-1-- D-1-- 7: A0-- B0-- C-1-- D--2- 8: A0-- B0-- C-1-- D--3 9: A0-- B0-- C--2- D0--- 10: A0-- B0-- C--2- D-1-- 11: A0-- B0-- C--2- D--2- 12: A0-- B0-- C--2- D--3 13: A0-- B0-- C--3 D0--- 14: A0-- B0-- C--3 D-1-- 15: A0-- B0-- C--3 D--2- 16: A0-- B0-- C--3 D--3 17: A0-- B-1-- C0-- D0--- 18: A0-- B-1-- C0-- D-1-- 19: A0-- B-1-- C0-- D--2- 20: A0-- B-1-- C0-- D--3 21: A0-- B-1-- C-1-- D0--- 22: A0-- B-1-- C-1-- D-1-- -fcase-strict-upper 23: A0-- B-1-- C-1-- D--2- 24: A0-- B-1-- C-1-- D--3 25: A0-- B-1-- C--2- D0--- 26: A0-- B-1-- C--2- D-1-- 27: A0-- B-1-- C--2- D--2- 28: A0-- B-1-- C--2- D--3 29: A0-- B-1-- C--3 D0--- 30: A0-- B-1-- C--3 D-1-- 31: A0-- B-1-- C--3 D--2- 32: A0-- B-1-- C--3 D--3 33: A0-- B--2- C0-- D0--- 34: A0-- B--2- C0-- D-1-- 35: A0-- B--2- C0-- D--2- 36: A0-- B--2- C0-- D--3 37: A0-- B--2- C-1-- D0--- 38: A0-- B--2- C-1-- D-1-- 39: A0-- B--2- C-1-- D--2- 40: A0-- B--2- C-1-- D--3 41: A0-- B--2- C--2- D0--- 42: A0-- B--2- C--2- D-1-- 43: A0-- B--2- C--2- D--2- -fcase-strict-lower 44: A0-- B--2- C--2- D--3 45: A0-- B--2- C--3 D0--- 46: A0-- B--2- C--3 D-1-- 47: A0-- B--2- C--3 D--2- 48: A0-- B--2- C--3 D--3 49: A0-- B--3 C0-- D0--- 50: A0-- B--3 C0-- D-1-- 51: A0-- B--3 C0-- D--2- 52: A0-- B--3 C0-- D--3 53: A0-- B--3 C-1-- D0--- 54: A0-- B--3 C-1-- D-1-- 55: A0-- B--3 C-1-- D--2- 56: A0-- B--3 C-1-- D--3 57: A0-- B--3 C--2- D0--- 58: A0-- B--3 C--2- D-1-- 59: A0-- B--3 C--2- D--2- 60: A0-- B--3 C--2- D--3 61: A0-- B--3 C--3 D0--- 62: A0-- B--3 C--3 D-1-- 63: A0-- B--3 C--3 D--2- 64: A0-- B--3 C--3 D--3 -fcase-initcap 65: A-1- B01-- C01-- D01-- -fcase-upper 66: A--2 B0-2- C0-2- D0-2- -fcase-lower
Number 22 is the "strict" ANSI FORTRAN 77 model wherein all input (except comments, character constants, and Hollerith strings) must be entered in uppercase. Use `-fcase-strict-upper' to specify this combination.
Number 43 is like Number 22 except all input must be lowercase. Use `-fcase-strict-lower' to specify this combination.
Number 65 is the "classic" ANSI FORTRAN 77 model as implemented on many non-UNIX machines whereby all the source is translated to uppercase. Use `-fcase-upper' to specify this combination.
Number 66 is the "canonical" UNIX model whereby all the source is translated to lowercase. Use `-fcase-lower' to specify this combination.
There are a few nearly useless combinations:
67: A-1- B01-- C01-- D--2- 68: A-1- B01-- C01-- D--3 69: A-1- B01-- C--23 D01-- 70: A-1- B01-- C--23 D--2- 71: A-1- B01-- C--23 D--3 72: A--2 B01-- C0-2- D-1-- 73: A--2 B01-- C0-2- D--3 74: A--2 B01-- C-1-3 D0-2- 75: A--2 B01-- C-1-3 D-1-- 76: A--2 B01-- C-1-3 D--3
The above allow some programs to be compiled but with restrictions that make most useful programs impossible: Numbers 67 and 72 warn about any user-defined symbol names (such as `SUBROUTINE FOO'); Numbers 68 and 73 warn about any user-defined symbol names longer than one character that don't have at least one non-alphabetic character after the first; Numbers 69 and 74 disallow any references to intrinsics; and Numbers 70, 71, 75, and 76 are combinations of the restrictions in 67+69, 68+69, 72+74, and 73+74, respectively.
All redundant combinations are shown in the above tables anyplace where more than one setting is shown for a low-level switch. For example, `B0-2-' means either setting 0 or 2 is valid for switch B. The "proper" setting in such a case is the one that copies the setting of switch A--any other setting might slightly reduce the speed of the compiler, though possibly to an unmeasurable extent.
All remaining combinations are useless in that they prevent successful compilation of non-null source files (source files with something other than comments).
g77
supports certain constructs that
have different meanings in VXT Fortran than they
do in the GNU Fortran language.
Generally, this manual uses the invented term VXT Fortran to refer VAX FORTRAN (circa v4). That compiler offered many popular features, though not necessarily those that are specific to the VAX processor architecture, the VMS operating system, or Digital Equipment Corporation's Fortran product line. (VAX and VMS probably are trademarks of Digital Equipment Corporation.)
An extension offered by a Digital Fortran product that also is
offered by several other Fortran products for different kinds of
systems is probably going to be considered for inclusion in g77
someday, and is considered a VXT Fortran feature.
The `-fvxt' option generally specifies that, where the meaning of a construct is ambiguous (means one thing in GNU Fortran and another in VXT Fortran), the VXT Fortran meaning is to be assumed.
g77
treats double-quote (`"')
as beginning an octal constant of INTEGER(KIND=1)
type
when the `-fvxt' option is specified.
The form of this octal constant is
"octal-digits
where octal-digits is a nonempty string of characters in the set `01234567'.
For example, the `-fvxt' option permits this:
PRINT *, "20 END
The above program would print the value `16'.
See section Integer Type, for information on the preferred construct for integer constants specified using GNU Fortran's octal notation.
(In the GNU Fortran language, the double-quote character (`"') delimits a character constant just as does apostrophe (`''). There is no way to allow both constructs in the general case, since statements like `PRINT *,"2000 !comment?"' would be ambiguous.)
g77
treats an exclamation point (`!') in column 6 of
a fixed-form source file
as a continuation character rather than
as the beginning of a comment
(as it does in any other column)
when the `-fvxt' option is specified.
The following program, when run, prints a message indicating whether it is interpreted according to GNU Fortran (and Fortran 90) rules or VXT Fortran rules:
C234567 (This line begins in column 1.) I = 0 !1 IF (I.EQ.0) PRINT *, ' I am a VXT Fortran program' IF (I.EQ.1) PRINT *, ' I am a Fortran 90 program' IF (I.LT.0 .OR. I.GT.1) PRINT *, ' I am a HAL 9000 computer' END
(In the GNU Fortran and Fortran 90 languages, exclamation point is a valid character and, unlike space (SPC) or zero (`0'), marks a line as a continuation line when it appears in column 6.)
The GNU Fortran language includes a number of features that are
part of Fortran 90, even when the `-ff90' option is not specified.
The features enabled by `-ff90' are intended to be those that,
when `-ff90' is not specified, would have another
meaning to g77
---usually meaning something invalid in the
GNU Fortran language.
So, the purpose of `-ff90' is not to specify whether g77
is
to gratuitously reject Fortran 90 constructs.
The `-pedantic' option specified with `-fno-f90' is intended
to do that, although its implementation is certainly incomplete at
this point.
When `-ff90' is specified:
COMPLEX
type,
is the same type as the real part of expr.
For example, assuming `Z' is type COMPLEX(KIND=2)
,
`REAL(Z)' would return a value of type REAL(KIND=2)
,
not of type REAL(KIND=1)
, since `-ff90' is specified.
The `-fpedantic' command-line option specifies that g77
is to warn about code that is not standard-conforming.
This is useful for finding
some extensions g77
accepts that other compilers might not accept.
(Note that the `-pedantic' and `-pedantic-errors' options
always imply `-fpedantic'.)
With `-fno-f90' in force, ANSI FORTRAN 77 is used as the standard for conforming code. With `-ff90' in force, Fortran 90 is used.
The constructs for which g77
issues diagnostics when `-fpedantic'
and `-fno-f90' are in force are:
SUBROUTINE X(N) REAL A(N) ...where `A' is not listed in any
ENTRY
statement,
and thus is not a dummy argument.
DOUBLE COMPLEX
, either explicitly or implicitly.
An explicit use of this type is via a DOUBLE COMPLEX
or
IMPLICIT DOUBLE COMPLEX
statement, for examples.
An example of an implicit use is the expression `C*D',
where `C' is COMPLEX(KIND=1)
and `D' is DOUBLE PRECISION
.
This expression is prohibited by ANSI FORTRAN 77
because the rules of promotion would suggest that it
produce a DOUBLE COMPLEX
result--a type not
provided for by that standard.
INTEGER(KIND=1)
in contexts such as:
GOTO
.
FORMAT
run-time expressions (not yet supported).
CHARACTER
entities in specification statements.
DO
constructs in DATA
statements.
LOGICAL
expressions to INTEGER
in contexts such as arithmetic IF
(where COMPLEX
expressions are disallowed anyway).
INTEGER I(10,20,4:2)
CHARACTER
entities, as in:
PRINT *, "
PRINT *, 'hello'(3:5)
PRINT *, FOO(,3)
COMMON
area is SAVE
d (for targets where program units in a single source
file are "glued" together as they typically are for UNIX development
environments).
COMMON
block.
DATA
statement.
(In the GNU Fortran language, `DATA I/1/' may be followed by `INTEGER J',
but not `INTEGER I'.
The `-fpedantic' option disallows both of these.)
CALL FOO; CALL BAR
CHARACTER
constants to initialize numeric entities, and vice
versa.
If `-fpedantic' is specified along with `-ff90', the following constructs result in diagnostics:
INCLUDE
directive.
The `-fugly-*' command-line options determine whether certain features supported by VAX FORTRAN and other such compilers, but considered too ugly to be in code that can be changed to use safer and/or more portable constructs, are accepted. These are humorously referred to as "distensions", extensions that just plain look ugly in the harsh light of day.
The `-fno-ugly-args' option disables passing typeless and Hollerith constants as actual arguments in procedure invocations. For example:
CALL FOO(4HABCD) CALL BAR('123'O)
These constructs can be too easily used to create non-portable code, but are not considered as "ugly" as others. Further, they are widely used in existing Fortran source code in ways that often are quite portable. Therefore, they are enabled by default.
The `-fugly-assumed' option enables the treatment of any array with a final dimension specified as `1' as an assumed-size array, as if `*' had been specified instead.
For example, `DIMENSION X(1)' is treated as if it
had read `DIMENSION X(*)' if `X' is listed as
a dummy argument in a preceding SUBROUTINE
, FUNCTION
,
or ENTRY
statement in the same program unit.
Use an explicit lower bound to avoid this interpretation. For example, `DIMENSION X(1:1)' is never treated as if it had read `DIMENSION X(*)' or `DIMENSION X(1:*)'. Nor is `DIMENSION X(2-1)' affected by this option, since that kind of expression is unlikely to have been intended to designate an assumed-size array.
This option is used to prevent warnings being issued about apparent out-of-bounds reference such as `X(2) = 99'.
It also prevents the array from being used in contexts that disallow assumed-size arrays, such as `PRINT *,X'. In such cases, a diagnostic is generated and the source file is not compiled.
The construct affected by this option is used only in old code that pre-exists the widespread acceptance of adjustable and assumed-size arrays in the Fortran community.
Note: This option does not affect how `DIMENSION X(1)' is
treated if `X' is listed as a dummy argument only
after the DIMENSION
statement (presumably in
an ENTRY
statement).
For example, `-fugly-assumed' has no effect on the
following program unit:
SUBROUTINE X REAL A(1) RETURN ENTRY Y(A) PRINT *, A END
The `-fugly-complex' option enables
use of the REAL()
and AIMAG()
intrinsics with arguments that are
COMPLEX
types other than COMPLEX(KIND=1)
.
With `-ff90' in effect, these intrinsics return the unconverted real and imaginary parts (respectively) of their argument.
With `-fno-f90' in effect, these intrinsics convert
the real and imaginary parts to REAL(KIND=1)
, and return
the result of that conversion.
Due to this ambiguity, the GNU Fortran language defines
these constructs as invalid, except in the specific
case where they are entirely and solely passed as an
argument to an invocation of the REAL()
intrinsic.
For example,
REAL(REAL(Z))
is permitted even when `Z' is COMPLEX(KIND=2)
and `-fno-ugly-complex' is in effect, because the
meaning is clear.
g77
enforces this restriction, unless `-fugly-complex'
is specified, in which case the appropriate interpretation is
chosen and no diagnostic is issued.
See section CMPAMBIG
, for information on how to cope with existing
code with unclear expectations of REAL()
and AIMAG()
with COMPLEX(KIND=2)
arguments.
See section RealPart Intrinsic, for information on the REALPART()
intrinsic, used to extract the real part of a complex expression
without conversion.
See section ImagPart Intrinsic, for information on the IMAGPART()
intrinsic, used to extract the imaginary part of a complex expression
without conversion.
The `-fugly-comma' option enables use of a single trailing comma to mean "pass an extra trailing null argument" in a list of actual arguments to an external procedure, and use of an empty list of arguments to such a procedure to mean "pass a single null argument".
(Null arguments often are used in some procedure-calling schemes to indicate omitted arguments.)
For example, `CALL FOO(,)' means "pass two null arguments", rather than "pass one null argument". Also, `CALL BAR()' means "pass one null argument".
This construct is considered "ugly" because it does not provide an elegant way to pass a single null argument that is syntactically distinct from passing no arguments. That is, this construct changes the meaning of code that makes no use of the construct.
So, with `-fugly-comma' in force, `CALL FOO()' and `I = JFUNC()' pass a single null argument, instead of passing no arguments as required by the Fortran 77 and 90 standards.
Note: Many systems gracefully allow the case where a procedure call passes one extra argument that the called procedure does not expect.
So, in practice, there might be no difference in the behavior of a program that does `CALL FOO()' or `I = JFUNC()' and is compiled with `-fugly-comma' in force as compared to its behavior when compiled with the default, `-fno-ugly-comma', in force, assuming `FOO' and `JFUNC' do not expect any arguments to be passed.
The constructs disabled by `-fno-ugly-init' are:
DATA
and PARAMETER
statements, plus
type-declaration statements specifying initial values.
Here are some sample initializations that are disabled by the
`-fno-ugly-init' option:
PARAMETER (VAL='9A304FFE'X) REAL*8 STRING/8HOUTPUT00/ DATA VAR/4HABCD/
INTEGER IA CHARACTER BELL PARAMETER (IA = 'A') PARAMETER (BELL = 7)
IVAR = 4HABCD PRINT *, IMAX0(2HAB, 2HBA)
The above constructs, when used, can tend to result in non-portable code. But, they are widely used in existing Fortran code in ways that often are quite portable. Therefore, they are enabled by default.
The constructs enabled via `-fugly-logint' are:
INTEGER
and LOGICAL
as
dictated by
context (typically implies nonportable dependencies on how a
particular implementation encodes .TRUE.
and .FALSE.
).
LOGICAL
variable in ASSIGN
and assigned-GOTO
statements.
The above constructs are disabled by default because use of them tends to lead to non-portable code. Even existing Fortran code that uses that often turns out to be non-portable, if not outright buggy.
Some of this is due to differences among implementations as
far as how .TRUE.
and .FALSE.
are encoded as
INTEGER
values--Fortran code that assumes a particular
coding is likely to use one of the above constructs, and is
also likely to not work correctly on implementations using
different encodings.
See section Equivalence Versus Equality, for more information.
The `-fugly-assign' option forces g77
to use the
same storage for assigned labels as it would for a normal
assignment to the same variable.
For example, consider the following code fragment:
I = 3 ASSIGN 10 TO I
Normally, for portability and improved diagnostics, g77
reserves distinct storage for a "sibling" of `I', used
only for ASSIGN
statements to that variable (along with
the corresponding assigned-GOTO
and assigned-FORMAT
-I/O
statements that reference the variable).
However, some code (that violates the ANSI FORTRAN 77 standard)
attempts to copy assigned labels among variables involved with
ASSIGN
statements, as in:
ASSIGN 10 TO I ISTATE(5) = I ... J = ISTATE(ICUR) GOTO J
Such code doesn't work under g77
unless `-fugly-assign'
is specified on the command-line, ensuring that the value of I
referenced in the second line is whatever value g77
uses
to designate statement label `10', so the value may be
copied into the `ISTATE' array, later retrieved into a
variable of the appropriate type (`J'), and used as the target of
an assigned-GOTO
statement.
Note: To avoid subtle program bugs,
when `-fugly-assign' is specified,
g77
requires the type of variables
specified in assigned-label contexts
must be the same type returned by %LOC()
.
On many systems, this type is effectively the same
as INTEGER(KIND=1)
, while, on others, it is
effectively the same as INTEGER(KIND=2)
.
Do not depend on g77
actually writing valid pointers
to these variables, however.
While g77
currently chooses that implementation, it might
be changed in the future.
See section Assigned Statement Labels (ASSIGN and GOTO), for implementation details on assigned-statement labels.