Fortran, best use of DIMENSION when initializing array with PARAMETER attribute

Viewed 141

In Fortran, are these two methods for initializing a parameter array identical? If not, what is the meaning of dimension(*)?

integer, parameter, dimension(2) :: x = [1,2]

vs

integer, parameter, dimension(*) :: x = [1,2]

1 Answers

The effect of both declarations is the same: a rank-1 named constant array of shape [2] with the obvious values.

Using dimension(*) makes the array implied shape rather than explicit shape: the named constant is of shape implied by the constant expression.

Which is better? Well, implied shape is not supported by all compilers (being a Fortran 2008 feature), but it saves worrying about writing shape twice.

Related