Array features not accepted in the Fortran standard

Recently I was reading the article “The array features in Fortran 8X with examples of their use” by Reid & Wilson (1985). I was bemused to find a number of features that are not part of Fortran today, and some which found their way under different names.

Here is a list of some of the features that appear were discussed at some point but ultimately dropped or covered by other language enhancements:

  • Array constructors

    • [10[1.3,2.7],7.1] returns an array of length 21 and contains [1.3,2.7] repeated ten times
    • [1:N] contains integers 1, 2, …, N
  • Array construction functions

    • DIAGONAL(VECTOR [,FILL]) Create a diagonal matrix
    • REPLICATE(ARRAY, DIM, NCOPIES) Replicates array by increasing a dimension
  • Identify statement
    IDENTIFY <I=1:N> DIAG(I) = A(I,I) permits the construction of subarrays that do not lie along the axes

  • Array geometric location functions

    • FIRSTLOC(MASK [,DIM]) and LASTLOC(MASK [,DIM] which were instead merged into FINDLOC(ARRAY, VALUE, DIM [, MASK] [,KIND] [,BACK])
    • PROJECT(ARRAY, MASK, BACKGROUND [, DIM]) Select masked values

I would be interested to learn the ultimate reasons to drop these array features? Particularly the array constructors seem like they would be quite useful.


The long road toward consensus that is Fortran standard revisions will invariably be full of roadkills!

With the 2 array constructors shown above, somewhat more verbose variants somehow managed to get voted in eventually!

   real, parameter :: a(*) = [ [( [1.3,2.7], integer :: i=1,10 )], 7.1 ]
   integer, parameter :: N = 5
   integer, parameter :: x(*) = [( i, integer :: i=1,N )] 
   print *, a
   print *, x

C:\Temp>ifort /standard-semantics a.f90
Intel(R) Fortran Intel(R) 64 Compiler Classic for applications running on Intel(R) 64, Version 2021.3.0 Build 20210609_000000
Copyright (C) 1985-2021 Intel Corporation. All rights reserved.

Microsoft (R) Incremental Linker Version 14.29.30038.1
Copyright (C) Microsoft Corporation. All rights reserved.


1.300000 2.700000 1.300000 2.700000 1.300000
2.700000 1.300000 2.700000 1.300000 2.700000
1.300000 2.700000 1.300000 2.700000 1.300000
2.700000 1.300000 2.700000 1.300000 2.700000
1 2 3 4 5


1 Like
real, parameter :: a(*) = [ [( [1.3,2.7], integer :: i=1,10 )], 7.1 ]

apparently (and according to common sense, I hope it is also standard-conforming), the middle [] are not required. Intel compiler happily accepts just

real, parameter :: a(*) = [ ( [1.3,2.7], integer :: i=1,10 ), 7.1 ]

Gfortran 10 does not recognize (yet?) the internal declarations so one has to remove integer :: from the constructors in above code.

1 Like

Yes, that’s correct; my snippet overspecified the brackets

What about gfortran 11 or 12 (experimental), perhaps this Fortran 2018 feature is supported in a later version of the compiler?

I am not aware of GCC-11. It is not available either in Ubuntu 20.04 or MacOS 11.3 Brew repository

gcc-11 was released in April 2021. It has been accepted e.g., into Debian’s branch experimental (gcc-11 tracker) only, which differs from the analogue about gcc-10. So it might be a bit early for Ubuntu and its LTS’es.

Update: gfortran-11 complains on the in-constructor declaration as well. Checked on updated ‘brew’ in MacOS 11.3

gfortran 11.1 is available in Ubuntu 21.04. But the default version is 10.3.

Fortran 2018, a minor revision per WG5, introduced a few facilities that books such as “Modern Fortran Explained” are prone to place under “miscellaneous enhancements”. Among other items, the feature introductions in Fortran 2018 include the following which help in working with arrays:

  • “Constant properties of an object declared in its entity-decl can be used in its initialization.”
  • “The type and kind of an implied DO variable in an array constructor … can be specified within the constructor …”

gfortran appears to have some Fortran 2018 items implemented while other features from the standard revision like the couple listed above are awaiting: Fortran2018Status - GCC Wiki

Which version is it? ‘gfcx’ is strange itself - is it an alias maybe? Could you post output of ‘gfcx -v’?
Mine is “gcc version 11.1.0 (Homebrew GCC 11.1.0_1)” and gives:

$ gfortran-11 -std=f2018 arrcons.f90

    2 |   real, parameter :: a(*) = [ ( [1.3,2.7], integer :: i=1,10 ), 7.1 ]
      |                                          1
Error: Expected a right parenthesis in expression at (1)

    4 |   integer, parameter :: x(*) = [( i, integer :: i=1,N )]
      |                                    1
Error: Expected a right parenthesis in expression at (1)