diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index 6dc9f5100ca..2ef7187710e 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,12 @@ +2007-01-03 Brooks Moses + + * gfortran.texi (GFORTRAN_DEFAULT_RECL): Added units + to description. + (Extensions): Miscellaneous minor rewriting and copyediting. + (BOZ-literal constants): Renamed from Hexadecimal constants. + (Hollerith constants support): Added explanation and + suggestions for standard-conforming modern equivalents. + 2007-01-03 Brooks Moses * intrinsic.texi: Improvements to index entries; change diff --git a/gcc/fortran/gfortran.texi b/gcc/fortran/gfortran.texi index 66202bec47c..13deb73c995 100644 --- a/gcc/fortran/gfortran.texi +++ b/gcc/fortran/gfortran.texi @@ -603,10 +603,10 @@ in most cases. Default is not to print plus signs. @node GFORTRAN_DEFAULT_RECL @section @env{GFORTRAN_DEFAULT_RECL}---Default record length for new files -This environment variable specifies the default record length for -files which are opened without a @code{RECL} tag in the @code{OPEN} -statement. This must be a positive integer. The default value is -1073741824. +This environment variable specifies the default record length, in +bytes, for files which are opened without a @code{RECL} tag in the +@code{OPEN} statement. This must be a positive integer. The +default value is 1073741824 bytes (1 GB). @node GFORTRAN_LIST_SEPARATOR @section @env{GFORTRAN_LIST_SEPARATOR}---Separator for list output @@ -811,14 +811,14 @@ of extensions, and @option{-std=legacy} allows both without warning. * Old-style kind specifications:: * Old-style variable initialization:: * Extensions to namelist:: -* X format descriptor:: +* X format descriptor without count field:: * Commas in FORMAT specifications:: * Missing period in FORMAT specifications:: * I/O item lists:: -* Hexadecimal constants:: +* BOZ literal constants:: * Real array indices:: * Unary operators:: -* Implicitly interconvert LOGICAL and INTEGER:: +* Implicitly convert LOGICAL and INTEGER values:: * Hollerith constants support:: * Cray pointers:: * CONVERT specifier:: @@ -834,10 +834,11 @@ declarations. These look like: @smallexample TYPESPEC*k x,y,z @end smallexample -where @code{TYPESPEC} is a basic type, and where @code{k} is a valid kind -number for that type. The statement then declares @code{x}, @code{y} -and @code{z} to be of type @code{TYPESPEC} with kind @code{k}. In -other words, it is equivalent to the standard conforming declaration +where @code{TYPESPEC} is a basic type (@code{INTEGER}, @code{REAL}, +etc.), and where @code{k} is a valid kind number for that type. The +statement then declares @code{x}, @code{y} and @code{z} to be of +type @code{TYPESPEC} with kind @code{k}. This is equivalent to the +standard conforming declaration @smallexample TYPESPEC(k) x,y,z @end smallexample @@ -849,30 +850,33 @@ other words, it is equivalent to the standard conforming declaration GNU Fortran allows old-style initialization of variables of the form: @smallexample - INTEGER*4 i/1/,j/2/ - REAL*8 x(2,2) /3*0.,1./ + INTEGER i/1/,j/2/ + REAL x(2,2) /3*0.,1./ @end smallexample -These are only allowed in declarations without double colons -(@code{::}), as these were introduced in Fortran 90 which also -introduced a new syntax for variable initializations. The syntax for -the individual initializers is as for the @code{DATA} statement, but +The syntax for the initializers is as for the @code{DATA} statement, but unlike in a @code{DATA} statement, an initializer only applies to the -variable immediately preceding. In other words, something like -@code{INTEGER I,J/2,3/} is not valid. +variable immediately preceding the initialization. In other words, +something like @code{INTEGER I,J/2,3/} is not valid. This style of +initialization is only allowed in declarations without double colons +(@code{::}); the double colons were introduced in Fortran 90, which also +introduced a standard syntax for initializating variables in type +declarations. -Examples of standard conforming code equivalent to the above example, are: +Examples of standard-conforming code equivalent to the above example +are: @smallexample ! Fortran 90 - INTEGER(4) :: i = 1, j = 2 - REAL(8) :: x(2,2) = RESHAPE((/0.,0.,0.,1./),SHAPE(x)) + INTEGER :: i = 1, j = 2 + REAL :: x(2,2) = RESHAPE((/0.,0.,0.,1./),SHAPE(x)) ! Fortran 77 - INTEGER i, j - DOUBLE PRECISION x(2,2) - DATA i,j,x /1,2,3*0.,1./ + INTEGER i, j + REAL x(2,2) + DATA i/1/, j/2/, x/3*0.,1./ @end smallexample -Note that variables initialized in type declarations -automatically acquire the @code{SAVE} attribute. +Note that variables which are explicitly initialized in declarations +or in @code{DATA} statements automatically acquire the @code{SAVE} +attribute. @node Extensions to namelist @section Extensions to namelist @@ -884,7 +888,7 @@ The output from a namelist write is compatible with namelist read. The output has all names in upper case and indentation to column 1 after the namelist name. Two extensions are permitted: -Old-style use of $ instead of & +Old-style use of @samp{$} instead of @samp{&} @smallexample $MYNML X(:)%Y(2) = 1.0 2.0 3.0 @@ -892,13 +896,14 @@ $MYNML $END @end smallexample -It should be noticed that the default terminator is / rather than &END. +It should be noted that the default terminator is @samp{/} rather than +@samp{&END}. Querying of the namelist when inputting from stdin. After at least -one space, entering ? sends to stdout the namelist name and the names of +one space, entering @samp{?} sends to stdout the namelist name and the names of the variables in the namelist: @smallexample -? + ? &mynml x @@ -907,8 +912,8 @@ the variables in the namelist: &end @end smallexample -Entering =? outputs the namelist to stdout, as if WRITE (*,NML = mynml) -had been called: +Entering @samp{=?} outputs the namelist to stdout, as if +@code{WRITE(*,NML = mynml)} had been called: @smallexample =? @@ -920,9 +925,10 @@ had been called: @end smallexample To aid this dialog, when input is from stdin, errors send their -messages to stderr and execution continues, even if IOSTAT is set. +messages to stderr and execution continues, even if @code{IOSTAT} is set. -PRINT namelist is permitted. This causes an error if -std=f95 is used. +@code{PRINT} namelist is permitted. This causes an error if +@option{-std=f95} is used. @smallexample PROGRAM test_print REAL, dimension (4) :: x = (/1.0, 2.0, 3.0, 4.0/) @@ -931,22 +937,23 @@ PROGRAM test_print END PROGRAM test_print @end smallexample -Expanded namelist reads are permitted. This causes an error if -std=f95 -is used. In the following example, the first element of the array will be -given the value 0.00 and succeeding elements will be 1.00 and 2.00. +Expanded namelist reads are permitted. This causes an error if +@option{-std=f95} is used. In the following example, the first element +of the array will be given the value 0.00 and the two succeeding +elements 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 -@section X format descriptor -@cindex X format descriptor +@node X format descriptor without count field +@section @code{X} format descriptor without count field +@cindex @code{X} format descriptor without count field -To support legacy codes, GNU Fortran permits the count field -of the X edit descriptor in FORMAT statements to be omitted. When -omitted, the count is implicitly assumed to be one. +To 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, 3 @@ -954,12 +961,12 @@ omitted, the count is implicitly assumed to be one. @end smallexample @node Commas in FORMAT specifications -@section Commas in FORMAT specifications -@cindex Commas in FORMAT specifications +@section Commas in @code{FORMAT} specifications +@cindex Commas in @code{FORMAT} specifications To support legacy codes, GNU Fortran allows the comma separator to be omitted immediately before and after character string edit -descriptors in FORMAT statements. +descriptors in @code{FORMAT} statements. @smallexample PRINT 10, 2, 3 @@ -968,12 +975,13 @@ descriptors in FORMAT statements. @node Missing period in FORMAT specifications -@section Missing period in FORMAT specifications -@cindex Missing period in FORMAT specifications +@section Missing period in @code{FORMAT} specifications +@cindex Missing period in @code{FORMAT} specifications To support legacy codes, GNU Fortran allows missing periods in format -specifications if and only if -std=legacy is given on the command line. This -is considered non-conforming code and is discouraged. +specifications if and only if @option{-std=legacy} is given on the +command line. This is considered non-conforming code and is +discouraged. @smallexample REAL :: value @@ -986,101 +994,116 @@ is considered non-conforming code and is discouraged. @cindex I/O item lists To support legacy codes, GNU Fortran allows the input item list -of the READ statement, and the output item lists of the WRITE and PRINT -statements to start with a comma. +of the @code{READ} statement, and the output item lists of the +@code{WRITE} and @code{PRINT} statements, to start with a comma. -@node Hexadecimal constants -@section Hexadecimal constants -@cindex Hexadecimal constants +@node BOZ literal constants +@section BOZ literal constants +@cindex BOZ literal constants -As an extension, GNU Fortran allows hexadecimal constants to +As an extension, GNU Fortran allows hexadecimal BOZ literal constants to be specified using the X prefix, in addition to the standard Z prefix. -BOZ literal constants can also be specified by adding a suffix to the string. -For example, @code{Z'ABC'} and @code{'ABC'Z} are the same constant. +BOZ literal constants can also be specified by adding a suffix to the +string. For example, @code{Z'ABC'} and @code{'ABC'Z} are equivalent. -The Fortran standard restricts the appearance of a BOZ literal constant to -the @code{DATA} statement, and it is expected to be assigned to an -@code{INTEGER} variable. GNU Fortran permits a BOZ literal to appear -in any initialization expression as well as assignment statements. +The Fortran standard restricts the appearance of a BOZ literal constant +to the @code{DATA} statement, and it is expected to be assigned to an +@code{INTEGER} variable. GNU Fortran permits a BOZ literal to appear in +any initialization expression as well as assignment statements. -Attempts to use a BOZ literal constant to do a bitwise initialization of a -variable can lead to confusion. A BOZ literal constant is converted to an -@code{INTEGER} value with the kind type with the largest decimal representation, -and this value is then converted numerically to the type and kind of the -variable in question. Thus, one should not expect a bitwise copy of the BOZ -literal constant to be assigned to a @code{REAL} variable. - -Similarly, initializing an @code{INTEGER} variable with a statement such as -@code{DATA i/Z'FFFFFFFF'/} will produce an integer overflow rather than the -desired result of @math{-1} when @code{i} is a 32-bit integer on a system that -supports 64-bit integers. The @samp{-fno-range-check} option can be used as -a workaround for legacy code that initializes integers in this manner. +Attempts to use a BOZ literal constant to do a bitwise initialization of +a variable can lead to confusion. A BOZ literal constant is converted +to an @code{INTEGER} value with the kind type with the largest decimal +representation, and this value is then converted numerically to the type +and kind of the variable in question. Thus, one should not expect a +bitwise copy of the BOZ literal constant to be assigned to a @code{REAL} +variable. +Similarly, initializing an @code{INTEGER} variable with a statement such +as @code{DATA i/Z'FFFFFFFF'/} will produce an integer overflow rather +than the desired result of @math{-1} when @code{i} is a 32-bit integer +on a system that supports 64-bit integers. The @samp{-fno-range-check} +option can be used as a workaround for legacy code that initializes +integers in this manner. @node Real array indices @section Real array indices @cindex Real array indices -As an extension, GNU Fortran allows arrays to be indexed using -real types, whose values are implicitly converted to integers. +As an extension, GNU Fortran allows the use of @code{REAL} expressions +or variables as array indices. @node Unary operators @section Unary operators @cindex Unary operators -As an extension, GNU Fortran allows unary plus and unary -minus operators to appear as the second operand of binary arithmetic -operators without the need for parenthesis. +As an extension, GNU Fortran allows unary plus and unary minus operators +to appear as the second operand of binary arithmetic operators without +the need for parenthesis. @smallexample X = Y * -Z @end smallexample -@node Implicitly interconvert LOGICAL and INTEGER -@section Implicitly interconvert LOGICAL and INTEGER -@cindex Implicitly interconvert LOGICAL and INTEGER +@node Implicitly convert LOGICAL and INTEGER values +@section Implicitly convert @code{LOGICAL} and @code{INTEGER} values +@cindex Implicitly convert @code{LOGICAL} and @code{INTEGER} values -As an extension for backwards compatibility with other compilers, -GNU Fortran allows the implicit conversion of LOGICALs to INTEGERs -and vice versa. When converting from a LOGICAL to an INTEGER, the numeric -value of @code{.FALSE.} is zero, and that of @code{.TRUE.} is one. When -converting from INTEGER to LOGICAL, the value zero is interpreted as +As an extension for backwards compatibility with other compilers, GNU +Fortran allows the implicit conversion of @code{LOGICAL} values to +@code{INTEGER} values and vice versa. When converting from a +@code{LOGICAL} to an @code{INTEGER}, @code{.FALSE.} is interpreted as +zero, and @code{.TRUE.} is interpreted as one. When converting from +@code{INTEGER} to @code{LOGICAL}, the value zero is interpreted as @code{.FALSE.} and any nonzero value is interpreted as @code{.TRUE.}. @smallexample - INTEGER*4 i - i = .FALSE. + INTEGER :: i = 1 + IF (i) PRINT *, 'True' @end smallexample @node Hollerith constants support @section Hollerith constants support @cindex Hollerith constants -A Hollerith constant is a string of characters preceded by the letter @samp{H} -or @samp{h}, and there must be an literal, unsigned, nonzero default integer -constant indicating the number of characters in the string. Hollerith constants -are stored as byte strings, one character per byte. +GNU Fortran supports Hollerith constants in assignments, function +arguments, and @code{DATA} and @code{ASSIGN} statements. A Hollerith +constant is written as a string of characters preceeded by an integer +constant indicating the character count, and the letter @code{H} or +@code{h}, and stored in bytewise fashion in a numeric (@code{INTEGER}, +@code{REAL}, or @code{complex}) or @code{LOGICAL} variable. The +constant will be padded or truncated to fit the size of the variable in +which it is stored. -GNU Fortran supports Hollerith constants. They can be used as the right -hands in the @code{DATA} statement and @code{ASSIGN} statement, also as the -arguments. The left hands can be of Integer, Real, Complex and Logical type. -The constant will be padded or truncated to fit the size of left hand. - -Valid Hollerith constants examples: +Examples of valid uses of Hollerith constants: @smallexample -complex*16 x(2) -data x /16Habcdefghijklmnop, 16Hqrstuvwxyz012345/ -call foo (4H abc) -x(1) = 16Habcdefghijklmnop + complex*16 x(2) + data x /16Habcdefghijklmnop, 16Hqrstuvwxyz012345/ + x(1) = 16HABCDEFGHIJKLMNOP + call foo (4h abc) @end smallexample Invalid Hollerith constants examples: @smallexample -integer*4 a -a = 8H12345678 ! The Hollerith constant is too long. It will be truncated. -a = 0H ! At least one character needed. + integer*4 a + a = 8H12345678 ! Valid, but the Hollerith constant will be truncated. + a = 0H ! At least one character is needed. @end smallexample +In general, Hollerith constants were used to provide a rudimentary +facility for handling character strings in early Fortran compilers, +prior to the introduction of @code{CHARACTER} variables in Fortran 77; +in those cases, the standard-compliant equivalent is to convert the +program to use proper character strings. On occasion, there may be a +case where the intent is specifically to initialize a numeric variable +with a given byte sequence. In these cases, the same result can be +obtained by using the @code{TRANSFER} statement, as in this example. +@smallexample + INTEGER(KIND=4) :: a + a = TRANSFER ("abcd", a) ! equivalent to: a = 4Habcd +@end smallexample + + @node Cray pointers @section Cray pointers @cindex Cray pointers @@ -1101,8 +1124,8 @@ or, The pointer is an integer that is intended to hold a memory address. The pointee may be an array or scalar. A pointee can be an assumed size array---that is, the last dimension may be left unspecified by -using a '*' in place of a value---but a pointee cannot be an assumed -shape array. No space is allocated for the pointee. +using a @code{*} in place of a value---but a pointee cannot be an +assumed shape array. No space is allocated for the pointee. The pointee may have its type declared before or after the pointer statement, and its array specification (if any) may be declared @@ -1133,17 +1156,16 @@ pointer in order to increment it. Consider the following example: ipt = loc (target) ipt = ipt + 1 @end smallexample -The last statement does not set ipt to the address of -@code{target(1)}, as one familiar with C pointer arithmetic might -expect. Adding 1 to ipt just adds one byte to the address stored in -ipt. +The last statement does not set @code{ipt} to the address of +@code{target(1)}, as it would in C pointer arithmetic. Adding @code{1} +to @code{ipt} just adds one byte to the address stored in @code{ipt}. Any expression involving the pointee will be translated to use the value stored in the pointer as the base address. To get the address of elements, this extension provides an intrinsic -function loc(), loc() is essentially the C '&' operator, except the -address is cast to an integer type: +function @code{LOC()}. The @code{LOC()} function is equivalent to the +@code{&} operator in C, except the address is cast to an integer type: @smallexample real ar(10) pointer(ipt, arpte(10)) @@ -1162,33 +1184,35 @@ example: pointer (ipt, iarr) ipt = loc(target) @end smallexample -As long as ipt remains unchanged, iarr is now an alias for target. -The optimizer, however, will not detect this aliasing, so it is unsafe -to use iarr and target simultaneously. Using a pointee in any way -that violates the Fortran aliasing rules or assumptions is illegal. -It is the user's responsibility to avoid doing this; the compiler -works under the assumption that no such aliasing occurs. +As long as @code{ipt} remains unchanged, @code{iarr} is now an alias for +@code{target}. The optimizer, however, will not detect this aliasing, so +it is unsafe to use @code{iarr} and @code{target} simultaneously. Using +a pointee in any way that violates the Fortran aliasing rules or +assumptions is illegal. It is the user's responsibility to avoid doing +this; the compiler works under the assumption that no such aliasing +occurs. -Cray pointers will work correctly when there is no aliasing (i.e., -when they're used to access a dynamically allocated block of memory), -and also in any routine where a pointee is used, but any variable with -which it shares storage is not used. Code that violates these rules -may not run as the user intends. This is not a bug in the optimizer; -any code that violates the aliasing rules is illegal. (Note that this -is not unique to GNU Fortran; any Fortran compiler that supports Cray -pointers will ``incorrectly'' optimize code with illegal aliasing.) +Cray pointers will work correctly when there is no aliasing (i.e., when +they are used to access a dynamically allocated block of memory), and +also in any routine where a pointee is used, but any variable with which +it shares storage is not used. Code that violates these rules may not +run as the user intends. This is not a bug in the optimizer; any code +that violates the aliasing rules is illegal. (Note that this is not +unique to GNU Fortran; any Fortran compiler that supports Cray pointers +will ``incorrectly'' optimize code with illegal aliasing.) -There are a number of restrictions on the attributes that can be -applied to Cray pointers and pointees. Pointees may not have the -attributes ALLOCATABLE, INTENT, OPTIONAL, DUMMY, TARGET, -INTRINSIC, or POINTER. Pointers may not have the attributes -DIMENSION, POINTER, TARGET, ALLOCATABLE, EXTERNAL, or INTRINSIC. +There are a number of restrictions on the attributes that can be applied +to Cray pointers and pointees. Pointees may not have the +@code{ALLOCATABLE}, @code{INTENT}, @code{OPTIONAL}, @code{DUMMY}, +@code{TARGET}, @code{INTRINSIC}, or @code{POINTER} attributes. Pointers +may not have the @code{DIMENSION}, @code{POINTER}, @code{TARGET}, +@code{ALLOCATABLE}, @code{EXTERNAL}, or @code{INTRINSIC} attributes. Pointees may not occur in more than one pointer statement. A pointee cannot be a pointer. Pointees cannot occur in equivalence, common, or data statements. -A Cray pointer may point to a function or a subroutine. For example, -the following excerpt is valid: +A Cray pointer may also point to a function or a subroutine. For +example, the following excerpt is valid: @smallexample implicit none external sub @@ -1244,12 +1268,13 @@ The value of the conversion can be queried by using on IEEE systems of kinds 4 and 8. Conversion between different ``extended double'' types on different architectures such as m68k and x86_64, which GNU Fortran -supports as @code{REAL(KIND=10)}, will probably not work. +supports as @code{REAL(KIND=10)} and @code{REAL(KIND=16)}, will +probably not work. @emph{Note that the values specified via the GFORTRAN_CONVERT_UNIT environment variable will override the CONVERT specifier in the open statement}. This is to give control over data formats to -a user who does not have the source code of his program available. +users who do not have the source code of their program available. Using anything but the native representation for unformatted data carries a significant speed overhead. If speed in this area matters