Next: Extensions to namelist, Previous: Old-style kind specifications, Up: Extensions implemented in GNU Fortran [Contents][Index]
GNU Fortran allows old-style initialization of variables of the form:
INTEGER i/1/,j/2/
REAL x(2,2) /3*0.,1./
The syntax for the initializers is as for the DATA statement, but
unlike in a DATA statement, an initializer only applies to the
variable immediately preceding the initialization. In other words,
something like INTEGER I,J/2,3/ is not valid. This style of
initialization is only allowed in declarations without double colons
(::); the double colons were introduced in Fortran 90, which also
introduced a standard syntax for initializing variables in type
declarations.
Examples of standard-conforming code equivalent to the above example are:
! 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./
Note that variables which are explicitly initialized in declarations
or in DATA statements automatically acquire the SAVE
attribute.